mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
luxd serves chain routes under /v1/chain, and the node, cli and sdk releases already ship it. The deployed gateways still answer the old prefix, so remote reads break until they are redeployed; the estate moves together rather than sitting half converted. Lines that record an observation - a probe, a status code, a past release - keep the prefix they were written against, as do URLs on hosts that are not ours. Avalanche endpoints move to /ext/bc, which is the path that host serves. Co-authored-by: Hanzo Dev <[email protected]>
80 lines
2.8 KiB
Go
80 lines
2.8 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package warp
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/luxfi/evm/rpc"
|
|
"github.com/luxfi/geth/common/hexutil"
|
|
"github.com/luxfi/ids"
|
|
)
|
|
|
|
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, chainIDStr string) ([]byte, error)
|
|
GetBlockSignature(ctx context.Context, blockID ids.ID) ([]byte, error)
|
|
GetBlockAggregateSignature(ctx context.Context, blockID ids.ID, quorumNum uint64, chainIDStr 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/v1/chain/%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) 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 {
|
|
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, chainIDStr string) ([]byte, error) {
|
|
var res hexutil.Bytes
|
|
if err := c.client.CallContext(ctx, &res, "warp_getMessageAggregateSignature", messageID, quorumNum, chainIDStr); 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, chainIDStr string) ([]byte, error) {
|
|
var res hexutil.Bytes
|
|
if err := c.client.CallContext(ctx, &res, "warp_getBlockAggregateSignature", blockID, quorumNum, chainIDStr); err != nil {
|
|
return nil, fmt.Errorf("call to warp_getBlockAggregateSignature failed. err: %w", err)
|
|
}
|
|
return res, nil
|
|
}
|