github.com/MetalBlockchain/subnet-evm@v0.4.9/warp/warp_client.go (about)

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