Skip to content

Commit

Permalink
Expose GetMessage in Warp API (ava-labs#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz authored Jan 23, 2024
1 parent 6f1c141 commit 210b337
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions warp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
var _ Client = (*client)(nil)

type Client interface {
GetMessage(ctx context.Context, messageID ids.ID) ([]byte, error)
GetMessageSignature(ctx context.Context, messageID ids.ID) ([]byte, error)
GetMessageAggregateSignature(ctx context.Context, messageID ids.ID, quorumNum uint64, subnetIDStr string) ([]byte, error)
GetBlockSignature(ctx context.Context, blockID ids.ID) ([]byte, error)
Expand All @@ -37,6 +38,14 @@ func NewClient(uri, chain string) (Client, error) {
}, nil
}

func (c *client) GetMessage(ctx context.Context, messageID ids.ID) ([]byte, error) {
var res hexutil.Bytes
if err := c.client.CallContext(ctx, &res, "warp_getMessage", messageID); err != nil {
return nil, fmt.Errorf("call to warp_getMessage failed. err: %w", err)
}
return res, nil
}

func (c *client) GetMessageSignature(ctx context.Context, messageID ids.ID) ([]byte, error) {
var res hexutil.Bytes
if err := c.client.CallContext(ctx, &res, "warp_getMessageSignature", messageID); err != nil {
Expand Down
9 changes: 9 additions & 0 deletions warp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func NewAPI(networkID uint32, sourceSubnetID ids.ID, sourceChainID ids.ID, state
}
}

// GetMessage returns the Warp message associated with a messageID.
func (a *API) GetMessage(ctx context.Context, messageID ids.ID) (hexutil.Bytes, error) {
message, err := a.backend.GetMessage(messageID)
if err != nil {
return nil, fmt.Errorf("failed to get message %s with error %w", messageID, err)
}
return hexutil.Bytes(message.Bytes()), nil
}

// GetMessageSignature returns the BLS signature associated with a messageID.
func (a *API) GetMessageSignature(ctx context.Context, messageID ids.ID) (hexutil.Bytes, error) {
signature, err := a.backend.GetMessageSignature(messageID)
Expand Down

0 comments on commit 210b337

Please sign in to comment.