Skip to content

Commit

Permalink
Added getContractSize api into rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Aug 23, 2024
1 parent 6208728 commit 7b8420d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/quaiapi/quai_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,24 @@ func (s *PublicBlockChainQuaiAPI) EstimateGas(ctx context.Context, args Transact
}
}

// GetContractSize gives the size of the contract at the block hash or number
func (s *PublicBlockChainQuaiAPI) GetContractSize(ctx context.Context, address common.AddressBytes, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error) {
addr := common.Bytes20ToAddress(address, s.b.NodeLocation())
if addr.IsInQuaiLedgerScope() {
state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
if state == nil || err != nil {
return nil, err
}
internal, err := addr.InternalAndQuaiAddress()
if err != nil {
return nil, err
}
return (*hexutil.Big)(state.GetSize(internal)), state.Error()
} else {
return nil, errors.New("getContractSize cannot be called on a Qi Address")
}
}

// BaseFee returns the base fee for a tx to be included in the next block.
// If txType is set to "true" returns the Quai base fee in units of Wei.
// If txType is set to "false" returns the Qi base fee in units of Qit.
Expand Down
6 changes: 6 additions & 0 deletions quaiclient/ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ func (ec *Client) BalanceAt(ctx context.Context, account common.MixedcaseAddress
return (*big.Int)(&result), err
}

func (ec *Client) ContractSizeAt(ctx context.Context, account common.MixedcaseAddress, blockNumber *big.Int) (*big.Int, error) {
var result hexutil.Big
err := ec.c.CallContext(ctx, &result, "quai_getContractSize", account.Original(), toBlockNumArg(blockNumber))
return (*big.Int)(&result), err
}

func (ec *Client) GetOutpointsByAddress(ctx context.Context, address common.MixedcaseAddress) (map[string]*types.OutpointAndDenomination, error) {
var outpoints map[string]*types.OutpointAndDenomination
err := ec.c.CallContext(ctx, &outpoints, "quai_getOutpointsByAddress", address.Original())
Expand Down

0 comments on commit 7b8420d

Please sign in to comment.