Skip to content

Support height as a string in avm.getBlockByHeight #1437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/common_args_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type GetBlockArgs struct {

// GetBlockByHeightArgs is the parameters supplied to the GetBlockByHeight API
type GetBlockByHeightArgs struct {
Height uint64 `json:"height"`
Height json.Uint64 `json:"height"`
Encoding formatting.Encoding `json:"encoding"`
}

Expand Down
27 changes: 13 additions & 14 deletions vms/avm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import (
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/formatting"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/utils/json"
"github.com/ava-labs/avalanchego/utils/rpc"

cjson "github.com/ava-labs/avalanchego/utils/json"
)

var _ Client = (*client)(nil)
Expand Down Expand Up @@ -251,7 +250,7 @@ func (c *client) GetBlock(ctx context.Context, blkID ids.ID, options ...rpc.Opti
func (c *client) GetBlockByHeight(ctx context.Context, height uint64, options ...rpc.Option) ([]byte, error) {
res := &api.FormattedBlock{}
err := c.requester.SendRequest(ctx, "avm.getBlockByHeight", &api.GetBlockByHeightArgs{
Height: height,
Height: json.Uint64(height),
Encoding: formatting.HexNC,
}, res, options...)
if err != nil {
Expand Down Expand Up @@ -349,7 +348,7 @@ func (c *client) GetAtomicUTXOs(
err := c.requester.SendRequest(ctx, "avm.getUTXOs", &api.GetUTXOsArgs{
Addresses: ids.ShortIDsToStrings(addrs),
SourceChain: sourceChain,
Limit: cjson.Uint32(limit),
Limit: json.Uint32(limit),
StartIndex: api.Index{
Address: startAddress.String(),
UTXO: startUTXOID.String(),
Expand Down Expand Up @@ -442,14 +441,14 @@ func (c *client) CreateAsset(
holders := make([]*Holder, len(clientHolders))
for i, clientHolder := range clientHolders {
holders[i] = &Holder{
Amount: cjson.Uint64(clientHolder.Amount),
Amount: json.Uint64(clientHolder.Amount),
Address: clientHolder.Address.String(),
}
}
minters := make([]Owners, len(clientMinters))
for i, clientMinter := range clientMinters {
minters[i] = Owners{
Threshold: cjson.Uint32(clientMinter.Threshold),
Threshold: json.Uint32(clientMinter.Threshold),
Minters: ids.ShortIDsToStrings(clientMinter.Minters),
}
}
Expand Down Expand Up @@ -483,7 +482,7 @@ func (c *client) CreateFixedCapAsset(
holders := make([]*Holder, len(clientHolders))
for i, clientHolder := range clientHolders {
holders[i] = &Holder{
Amount: cjson.Uint64(clientHolder.Amount),
Amount: json.Uint64(clientHolder.Amount),
Address: clientHolder.Address.String(),
}
}
Expand Down Expand Up @@ -516,7 +515,7 @@ func (c *client) CreateVariableCapAsset(
minters := make([]Owners, len(clientMinters))
for i, clientMinter := range clientMinters {
minters[i] = Owners{
Threshold: cjson.Uint32(clientMinter.Threshold),
Threshold: json.Uint32(clientMinter.Threshold),
Minters: ids.ShortIDsToStrings(clientMinter.Minters),
}
}
Expand Down Expand Up @@ -548,7 +547,7 @@ func (c *client) CreateNFTAsset(
minters := make([]Owners, len(clientMinters))
for i, clientMinter := range clientMinters {
minters[i] = Owners{
Threshold: cjson.Uint32(clientMinter.Threshold),
Threshold: json.Uint32(clientMinter.Threshold),
Minters: ids.ShortIDsToStrings(clientMinter.Minters),
}
}
Expand Down Expand Up @@ -623,7 +622,7 @@ func (c *client) Send(
JSONChangeAddr: api.JSONChangeAddr{ChangeAddr: changeAddr.String()},
},
SendOutput: SendOutput{
Amount: cjson.Uint64(amount),
Amount: json.Uint64(amount),
AssetID: assetID,
To: to.String(),
},
Expand All @@ -645,7 +644,7 @@ func (c *client) SendMultiple(
outputs := make([]SendOutput, len(clientOutputs))
for i, clientOutput := range clientOutputs {
outputs[i] = SendOutput{
Amount: cjson.Uint64(clientOutput.Amount),
Amount: json.Uint64(clientOutput.Amount),
AssetID: clientOutput.AssetID,
To: clientOutput.To.String(),
}
Expand Down Expand Up @@ -679,7 +678,7 @@ func (c *client) Mint(
JSONFromAddrs: api.JSONFromAddrs{From: ids.ShortIDsToStrings(from)},
JSONChangeAddr: api.JSONChangeAddr{ChangeAddr: changeAddr.String()},
},
Amount: cjson.Uint64(amount),
Amount: json.Uint64(amount),
AssetID: assetID,
To: to.String(),
}, res, options...)
Expand All @@ -704,7 +703,7 @@ func (c *client) SendNFT(
JSONChangeAddr: api.JSONChangeAddr{ChangeAddr: changeAddr.String()},
},
AssetID: assetID,
GroupID: cjson.Uint32(groupID),
GroupID: json.Uint32(groupID),
To: to.String(),
}, res, options...)
return res.TxID, err
Expand Down Expand Up @@ -767,7 +766,7 @@ func (c *client) Export(
JSONFromAddrs: api.JSONFromAddrs{From: ids.ShortIDsToStrings(from)},
JSONChangeAddr: api.JSONChangeAddr{ChangeAddr: changeAddr.String()},
},
Amount: cjson.Uint64(amount),
Amount: json.Uint64(amount),
TargetChain: targetChain,
To: to.String(),
AssetID: assetID,
Expand Down
4 changes: 2 additions & 2 deletions vms/avm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ func (s *Service) GetBlockByHeight(_ *http.Request, args *api.GetBlockByHeightAr
s.vm.ctx.Log.Debug("API called",
zap.String("service", "avm"),
zap.String("method", "getBlockByHeight"),
zap.Uint64("height", args.Height),
zap.Uint64("height", uint64(args.Height)),
)

if s.vm.chainManager == nil {
return errNotLinearized
}
reply.Encoding = args.Encoding

blockID, err := s.vm.state.GetBlockID(args.Height)
blockID, err := s.vm.state.GetBlockID(uint64(args.Height))
if err != nil {
return fmt.Errorf("couldn't get block at height %d: %w", args.Height, err)
}
Expand Down
2 changes: 1 addition & 1 deletion vms/avm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2975,7 +2975,7 @@ func TestServiceGetBlockByHeight(t *testing.T) {
service, expected := tt.serviceAndExpectedBlockFunc(ctrl)

args := &api.GetBlockByHeightArgs{
Height: blockHeight,
Height: json.Uint64(blockHeight),
Encoding: tt.encoding,
}
reply := &api.GetBlockResponse{}
Expand Down