diff --git a/relayer.go b/relayer.go index 2531a0b..0a535c9 100644 --- a/relayer.go +++ b/relayer.go @@ -17,6 +17,15 @@ 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 @@ -24,6 +33,9 @@ type Relayer interface { // .. 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) diff --git a/relayer/local_relayer.go b/relayer/local_relayer.go index d4fee81..51e56eb 100644 --- a/relayer/local_relayer.go +++ b/relayer/local_relayer.go @@ -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) diff --git a/relayer/rpc_relayer.go b/relayer/rpc_relayer.go index bff234b..2e49bc8 100644 --- a/relayer/rpc_relayer.go +++ b/relayer/rpc_relayer.go @@ -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, @@ -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