Skip to content
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

Expose GetMessage in Warp API #465

Merged
merged 1 commit into from
Jan 23, 2024
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
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
Loading