Skip to content

Commit

Permalink
quai_api: proper unmarshalling of block
Browse files Browse the repository at this point in the history
  • Loading branch information
shreekarashastry committed Jul 21, 2022
1 parent 276bcbc commit 307921d
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions internal/ethapi/quai_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,28 @@ func (s *PublicBlockChainQuaiAPI) GetBlockStatus(ctx context.Context, raw json.R
}

func (s *PublicBlockChainQuaiAPI) HLCRReorg(ctx context.Context, raw json.RawMessage) (bool, error) {
var block *types.Block
if err := json.Unmarshal(raw, &block); err != nil {
return false, nil
// Decode header and transactions.
var head *types.Header
var body rpcBlock
if err := json.Unmarshal(raw, &head); err != nil {
return false, err
}
if err := json.Unmarshal(raw, &body); err != nil {
return false, err
}

// Load uncles because they are not included in the block response.
txs := make([]*types.Transaction, len(body.Transactions))
for i, tx := range body.Transactions {
txs[i] = tx.tx
}

uncles := make([]*types.Header, len(body.Uncles))
for i, uncle := range body.Uncles {
uncles[i] = uncle
}

block := types.NewBlockWithHeader(head).WithBody(txs, uncles)
fmt.Println("Header", block.Hash())
return s.b.HLCRReorg(block)
}
Expand Down

0 comments on commit 307921d

Please sign in to comment.