-
Notifications
You must be signed in to change notification settings - Fork 218
/
warp_client.go
45 lines (37 loc) · 1.19 KB
/
warp_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// (c) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package warp
import (
"context"
"fmt"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/subnet-evm/rpc"
"github.com/ethereum/go-ethereum/common/hexutil"
)
var _ WarpClient = (*warpClient)(nil)
type WarpClient interface {
GetSignature(ctx context.Context, messageID ids.ID) ([]byte, error)
}
// warpClient implementation for interacting with EVM [chain]
type warpClient struct {
client *rpc.Client
}
// NewWarpClient returns a WarpClient for interacting with EVM [chain]
func NewWarpClient(uri, chain string) (WarpClient, error) {
client, 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 &warpClient{
client: client,
}, nil
}
// GetSignature requests the BLS signature associated with a messageID
func (c *warpClient) GetSignature(ctx context.Context, messageID ids.ID) ([]byte, error) {
var res hexutil.Bytes
err := c.client.CallContext(ctx, &res, "warp_getSignature", messageID)
if err != nil {
return nil, fmt.Errorf("call to warp_getSignature failed. err: %w", err)
}
return res, err
}