@@ -29,9 +29,12 @@ import (
29
29
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/eth/rpcclient"
30
30
ethtypes "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/eth/types"
31
31
"github.com/BitBoxSwiss/bitbox-wallet-app/util/errp"
32
+ "github.com/BitBoxSwiss/bitbox-wallet-app/util/logging"
32
33
"github.com/ethereum/go-ethereum"
33
34
"github.com/ethereum/go-ethereum/common"
35
+ "github.com/ethereum/go-ethereum/common/hexutil"
34
36
"github.com/ethereum/go-ethereum/core/types"
37
+ "github.com/sirupsen/logrus"
35
38
"golang.org/x/time/rate"
36
39
)
37
40
@@ -45,6 +48,8 @@ type Blockbook struct {
45
48
url string
46
49
httpClient * http.Client
47
50
limiter * rate.Limiter
51
+ // TODO remove before merging into master?
52
+ log * logrus.Entry
48
53
}
49
54
50
55
// NewBlockbook creates a new instance of EtherScan.
@@ -54,6 +59,7 @@ func NewBlockbook(chainId string, httpClient *http.Client) *Blockbook {
54
59
url : "https://bb1.shiftcrypto.io/api/" ,
55
60
httpClient : httpClient ,
56
61
limiter : rate .NewLimiter (rate .Limit (callsPerSec ), 1 ),
62
+ log : logging .Get ().WithField ("ETH Client" , "Blockbook" ),
57
63
}
58
64
}
59
65
@@ -129,7 +135,33 @@ func (blockbook *Blockbook) Transactions(blockTipHeight *big.Int, address common
129
135
130
136
// SendTransaction implements rpc.Interface.
131
137
func (blockbook * Blockbook ) SendTransaction (ctx context.Context , tx * types.Transaction ) error {
132
- return fmt .Errorf ("Not yet implemented" )
138
+ params := url.Values {}
139
+
140
+ result := struct {
141
+ Txid string `json:"result,omitempty"`
142
+ Error struct {
143
+ Message string `json:"message,omitempty"`
144
+ } `json:"error,omitempty"`
145
+ }{}
146
+
147
+ encodedTx , err := tx .MarshalBinary ()
148
+ if err != nil {
149
+ blockbook .log .Errorf ("Failed to marshal transaction: %v" , err )
150
+ return errp .WithStack (err )
151
+ }
152
+
153
+ if err := blockbook .call (ctx , path .Join ("sendtx" , hexutil .Encode (encodedTx )), params , & result ); err != nil {
154
+ blockbook .log .Errorf ("Failed to send transaction: %v" , err )
155
+ return errp .WithStack (err )
156
+ }
157
+
158
+ if result .Error .Message != "" {
159
+ blockbook .log .Errorf ("Error sending transaction: %s" , result .Error .Message )
160
+ return errp .Newf ("error sending transaction: %s" , result .Error .Message )
161
+ }
162
+
163
+ blockbook .log .Infof ("Transaction sent: %s" , result .Txid )
164
+ return nil
133
165
}
134
166
135
167
// ERC20Balance implements rpc.Interface.
0 commit comments