mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
)
|
|
|
|
var _ API = (*APIClient)(nil)
|
|
|
|
type APIClient struct {
|
|
rpc rpcClient
|
|
}
|
|
|
|
func NewClient(endpoint string) (*APIClient, error) {
|
|
clt, err := rpc.Dial(endpoint)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return NewClientFromRPC(clt), nil
|
|
}
|
|
|
|
type rpcClient interface {
|
|
CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
|
|
}
|
|
|
|
func NewClientFromRPC(rpc rpcClient) *APIClient {
|
|
return &APIClient{rpc: rpc}
|
|
}
|
|
|
|
func (a *APIClient) NewSession(ctx context.Context) (string, error) {
|
|
var id string
|
|
err := a.rpc.CallContext(ctx, &id, "suavex_newSession")
|
|
return id, err
|
|
}
|
|
|
|
func (a *APIClient) AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error) {
|
|
var receipt *types.SimulateTransactionResult
|
|
err := a.rpc.CallContext(ctx, &receipt, "suavex_addTransaction", sessionId, tx)
|
|
return receipt, err
|
|
}
|
|
|
|
func (a *APIClient) AddBundle(ctx context.Context, sessionId string, bundle Bundle) error {
|
|
return a.rpc.CallContext(ctx, nil, "suavex_addBundle", sessionId, bundle)
|
|
}
|