Skip to content

Commit

Permalink
api: changes due to underlying pkg update
Browse files Browse the repository at this point in the history
  • Loading branch information
qianbin committed Feb 2, 2024
1 parent dbbcb58 commit ef35a00
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions api/accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func New(

func (a *Accounts) getCode(addr thor.Address, summary *chain.BlockSummary) ([]byte, error) {
code, err := a.stater.
NewState(summary.Header.StateRoot(), summary.Header.Number(), summary.Conflicts, summary.SteadyNum).
NewState(summary.Root()).
GetCode(addr)
if err != nil {
return nil, err
Expand All @@ -74,7 +74,7 @@ func (a *Accounts) handleGetCode(w http.ResponseWriter, req *http.Request) error
}

func (a *Accounts) getAccount(addr thor.Address, summary *chain.BlockSummary) (*Account, error) {
state := a.stater.NewState(summary.Header.StateRoot(), summary.Header.Number(), summary.Conflicts, summary.SteadyNum)
state := a.stater.NewState(summary.Root())
b, err := state.GetBalance(addr)
if err != nil {
return nil, err
Expand All @@ -97,7 +97,7 @@ func (a *Accounts) getAccount(addr thor.Address, summary *chain.BlockSummary) (*

func (a *Accounts) getStorage(addr thor.Address, key thor.Bytes32, summary *chain.BlockSummary) (thor.Bytes32, error) {
storage, err := a.stater.
NewState(summary.Header.StateRoot(), summary.Header.Number(), summary.Conflicts, summary.SteadyNum).
NewState(summary.Root()).
GetStorage(addr, key)

if err != nil {
Expand Down Expand Up @@ -200,7 +200,7 @@ func (a *Accounts) batchCall(ctx context.Context, batchCallData *BatchCallData,
return nil, err
}
header := summary.Header
state := a.stater.NewState(header.StateRoot(), header.Number(), summary.Conflicts, summary.SteadyNum)
state := a.stater.NewState(summary.Root())

signer, _ := header.Signer()
rt := runtime.New(a.repo.NewChain(header.ParentID()), state,
Expand Down
2 changes: 1 addition & 1 deletion api/accounts/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func packTx(repo *chain.Repository, stater *state.Stater, transaction *tx.Transa
if _, err := stage.Commit(); err != nil {
t.Fatal(err)
}
if err := repo.AddBlock(b, receipts, 0); err != nil {
if err := repo.AddBlock(b, receipts, 0, false); err != nil {
t.Fatal(err)
}
if err := repo.SetBestBlockID(b.Header().ID()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/blocks/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func initBlockServer(t *testing.T) {
if _, err := stage.Commit(); err != nil {
t.Fatal(err)
}
if err := repo.AddBlock(block, receipts, 0); err != nil {
if err := repo.AddBlock(block, receipts, 0, false); err != nil {
t.Fatal(err)
}
if err := repo.SetBestBlockID(block.Header().ID()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (d *Debug) handleTraceCall(w http.ResponseWriter, req *http.Request) error

func (d *Debug) traceCall(ctx context.Context, tracer tracers.Tracer, summary *chain.BlockSummary, txCtx *xenv.TransactionContext, gas uint64, clause *tx.Clause) (interface{}, error) {
header := summary.Header
state := d.stater.NewState(header.StateRoot(), header.Number(), summary.Conflicts, summary.SteadyNum)
state := d.stater.NewState(summary.Root())
signer, _ := header.Signer()
rt := runtime.New(
d.repo.NewChain(header.ID()),
Expand Down
16 changes: 8 additions & 8 deletions api/transactions/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (t *Transactions) getRawTransaction(txID thor.Bytes32, head thor.Bytes32, a
return nil, err
}

summary, err := t.repo.GetBlockSummary(meta.BlockID)
header, err := chain.GetBlockHeader(meta.BlockNum)
if err != nil {
return nil, err
}
Expand All @@ -62,9 +62,9 @@ func (t *Transactions) getRawTransaction(txID thor.Bytes32, head thor.Bytes32, a
return &rawTransaction{
RawTx: RawTx{hexutil.Encode(raw)},
Meta: &TxMeta{
BlockID: summary.Header.ID(),
BlockNumber: summary.Header.Number(),
BlockTimestamp: summary.Header.Timestamp(),
BlockID: header.ID(),
BlockNumber: header.Number(),
BlockTimestamp: header.Timestamp(),
},
}, nil
}
Expand All @@ -84,11 +84,11 @@ func (t *Transactions) getTransactionByID(txID thor.Bytes32, head thor.Bytes32,
return nil, err
}

summary, err := t.repo.GetBlockSummary(meta.BlockID)
header, err := chain.GetBlockHeader(meta.BlockNum)
if err != nil {
return nil, err
}
return convertTransaction(tx, summary.Header), nil
return convertTransaction(tx, header), nil
}

// GetTransactionReceiptByID get tx's receipt
Expand All @@ -107,12 +107,12 @@ func (t *Transactions) getTransactionReceiptByID(txID thor.Bytes32, head thor.By
return nil, err
}

summary, err := t.repo.GetBlockSummary(meta.BlockID)
header, err := chain.GetBlockHeader(meta.BlockNum)
if err != nil {
return nil, err
}

return convertReceipt(receipt, summary.Header, tx)
return convertReceipt(receipt, header, tx)
}
func (t *Transactions) handleSendTransaction(w http.ResponseWriter, req *http.Request) error {
var rawTx *RawTx
Expand Down
2 changes: 1 addition & 1 deletion api/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func initTransactionServer(t *testing.T) {
if _, err := stage.Commit(); err != nil {
t.Fatal(err)
}
if err := repo.AddBlock(b, receipts, 0); err != nil {
if err := repo.AddBlock(b, receipts, 0, false); err != nil {
t.Fatal(err)
}
if err := repo.SetBestBlockID(b.Header().ID()); err != nil {
Expand Down

0 comments on commit ef35a00

Please sign in to comment.