Skip to content

Commit

Permalink
Update sequence.Relayer interface to have simulate method (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
marino39 authored Dec 18, 2023
1 parent 0437303 commit 3939186
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
12 changes: 12 additions & 0 deletions relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@ import (
"github.com/0xsequence/go-sequence/core"
)

type RelayerSimulateResult struct {
Executed bool
Succeeded bool
Result *string
Reason *string
GasUsed uint
GasLimit uint
}

type Relayer interface {
// ..
GetProvider() *ethrpc.Provider

// ..
EstimateGasLimits(ctx context.Context, walletConfig core.WalletConfig, walletContext WalletContext, txns Transactions) (Transactions, error)

// ..
Simulate(ctx context.Context, txs *SignedTransactions) ([]*RelayerSimulateResult, error)

// NOTE: nonce space is 160 bits wide
GetNonce(ctx context.Context, walletConfig core.WalletConfig, walletContext WalletContext, space *big.Int, blockNum *big.Int) (*big.Int, error)

Expand Down
5 changes: 5 additions & 0 deletions relayer/local_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func (r *LocalRelayer) GetNonce(ctx context.Context, walletConfig core.WalletCon
return sequence.GetWalletNonce(r.GetProvider(), walletConfig, walletContext, space, blockNum)
}

func (r *LocalRelayer) Simulate(ctx context.Context, txs *sequence.SignedTransactions) ([]*sequence.RelayerSimulateResult, error) {
//TODO implement me
panic("implement me")
}

func (r *LocalRelayer) Relay(ctx context.Context, signedTxs *sequence.SignedTransactions) (sequence.MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error) {
// NOTE: this implementation assumes the wallet is deployed and does not do automatic bundle creation (aka prepending / bundling
// a wallet creation call)
Expand Down
20 changes: 18 additions & 2 deletions relayer/rpc_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (r *RpcRelayer) GetNonce(ctx context.Context, walletConfig core.WalletConfi
return &nonce, nil
}

func (r *RpcRelayer) Simulate(ctx context.Context, txs *sequence.SignedTransactions) ([]*proto.SimulateResult, error) {
func (r *RpcRelayer) Simulate(ctx context.Context, txs *sequence.SignedTransactions) ([]*sequence.RelayerSimulateResult, error) {
to, execdata, err := sequence.EncodeTransactionsForRelaying(
r,
txs.WalletAddress,
Expand All @@ -122,7 +122,23 @@ func (r *RpcRelayer) Simulate(ctx context.Context, txs *sequence.SignedTransacti
return nil, err
}

return r.Service.Simulate(ctx, to.String(), "0x"+common.Bytes2Hex(execdata))
res, err := r.Service.Simulate(ctx, to.String(), "0x"+common.Bytes2Hex(execdata))
if err != nil {
return nil, err
}

var results []*sequence.RelayerSimulateResult
for _, r := range res {
results = append(results, &sequence.RelayerSimulateResult{
Executed: r.Executed,
Succeeded: r.Succeeded,
Result: r.Result,
Reason: r.Reason,
GasUsed: r.GasUsed,
GasLimit: r.GasLimit,
})
}
return results, nil
}

// Relay will submit the Sequence signed meta transaction to the relayer. The method will block until the relayer
Expand Down

0 comments on commit 3939186

Please sign in to comment.