This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transactor.go
84 lines (72 loc) · 2.26 KB
/
transactor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package rockside
import (
"context"
"math/big"
"sync"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
)
var (
_ bind.ContractTransactor = (*Transactor)(nil)
)
func TransactOpts() *bind.TransactOpts {
return &bind.TransactOpts{Signer: noopSigner()}
}
func noopSigner() bind.SignerFn {
return func(s types.Signer, c common.Address, t *types.Transaction) (*types.Transaction, error) {
return t, nil
}
}
type Transactor struct {
client *Client
rocksideSmartWallet common.Address
mu sync.RWMutex
Transaction map[common.Hash]string
}
func NewTransactor(rocksideSmartWallet common.Address, client *Client) *Transactor {
return &Transactor{
client: client,
rocksideSmartWallet: rocksideSmartWallet,
Transaction: make(map[common.Hash]string),
}
}
func (t *Transactor) ReturnRocksideTransactionHash(hash common.Hash) string {
t.mu.Lock()
defer t.mu.Unlock()
if txhash, ok := t.Transaction[hash]; ok {
delete(t.Transaction, hash)
return txhash
}
return ""
}
func (t *Transactor) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) {
return t.client.RPCClient.PendingCodeAt(ctx, account)
}
func (t *Transactor) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) {
return 0, nil // Rockside manage the nonce
}
func (t *Transactor) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
return t.client.RPCClient.SuggestGasPrice(ctx)
}
func (t *Transactor) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) {
return 0, nil // Rockside manage the gas
}
func (t *Transactor) SendTransaction(ctx context.Context, tx *types.Transaction) error {
resp, err := t.client.Transaction.Send(Transaction{
From: t.rocksideSmartWallet.String(),
To: tx.To().String(),
Value: hexutil.EncodeBig(tx.Value()),
Data: hexutil.Encode(tx.Data()),
Gas: hexutil.EncodeUint64(tx.Gas()),
GasPrice: hexutil.EncodeBig(tx.GasPrice()),
})
if err == nil {
t.mu.Lock()
defer t.mu.Unlock()
t.Transaction[tx.Hash()] = resp.TransactionHash
}
return err
}