mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
71 lines
2.5 KiB
Go
71 lines
2.5 KiB
Go
// (c) 2023-2024, Lux Partners Limited. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package warp
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/luxdefi/node/ids"
|
|
"github.com/luxdefi/evm/rpc"
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
)
|
|
|
|
var _ Client = (*client)(nil)
|
|
|
|
type Client interface {
|
|
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)
|
|
GetBlockAggregateSignature(ctx context.Context, blockID ids.ID, quorumNum uint64, subnetIDStr string) ([]byte, error)
|
|
}
|
|
|
|
// client implementation for interacting with EVM [chain]
|
|
type client struct {
|
|
client *rpc.Client
|
|
}
|
|
|
|
// NewClient returns a Client for interacting with EVM [chain]
|
|
func NewClient(uri, chain string) (Client, error) {
|
|
innerClient, err := rpc.Dial(fmt.Sprintf("%s/ext/bc/%s/rpc", uri, chain))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to dial client. err: %w", err)
|
|
}
|
|
return &client{
|
|
client: innerClient,
|
|
}, 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 {
|
|
return nil, fmt.Errorf("call to warp_getMessageSignature failed. err: %w", err)
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func (c *client) GetMessageAggregateSignature(ctx context.Context, messageID ids.ID, quorumNum uint64, subnetIDStr string) ([]byte, error) {
|
|
var res hexutil.Bytes
|
|
if err := c.client.CallContext(ctx, &res, "warp_getMessageAggregateSignature", messageID, quorumNum, subnetIDStr); err != nil {
|
|
return nil, fmt.Errorf("call to warp_getMessageAggregateSignature failed. err: %w", err)
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func (c *client) GetBlockSignature(ctx context.Context, blockID ids.ID) ([]byte, error) {
|
|
var res hexutil.Bytes
|
|
if err := c.client.CallContext(ctx, &res, "warp_getBlockSignature", blockID); err != nil {
|
|
return nil, fmt.Errorf("call to warp_getBlockSignature failed. err: %w", err)
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func (c *client) GetBlockAggregateSignature(ctx context.Context, blockID ids.ID, quorumNum uint64, subnetIDStr string) ([]byte, error) {
|
|
var res hexutil.Bytes
|
|
if err := c.client.CallContext(ctx, &res, "warp_getBlockAggregateSignature", blockID, quorumNum, subnetIDStr); err != nil {
|
|
return nil, fmt.Errorf("call to warp_getBlockAggregateSignature failed. err: %w", err)
|
|
}
|
|
return res, nil
|
|
}
|