Skip to content

Commit 66e7574

Browse files
committed
backend: add SendTransaction implementation for blockbook.
1 parent 52ee531 commit 66e7574

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

backend/coins/eth/blockbook/blockbook.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/BitBoxSwiss/bitbox-wallet-app/util/errp"
3232
"github.com/ethereum/go-ethereum"
3333
"github.com/ethereum/go-ethereum/common"
34+
"github.com/ethereum/go-ethereum/common/hexutil"
3435
"github.com/ethereum/go-ethereum/core/types"
3536
"golang.org/x/time/rate"
3637
)
@@ -129,7 +130,33 @@ func (blockbook *Blockbook) Transactions(blockTipHeight *big.Int, address common
129130

130131
// SendTransaction implements rpc.Interface.
131132
func (blockbook *Blockbook) SendTransaction(ctx context.Context, tx *types.Transaction) error {
132-
return fmt.Errorf("Not yet implemented")
133+
params := url.Values{}
134+
135+
result := struct {
136+
Txid string `json:"result,omitempty"`
137+
Error struct {
138+
Message string `json:"message,omitempty"`
139+
} `json:"error,omitempty"`
140+
}{}
141+
142+
encodedTx, err := tx.MarshalBinary()
143+
if err != nil {
144+
blockbook.log.Errorf("Failed to marshal transaction: %v", err)
145+
return errp.WithStack(err)
146+
}
147+
148+
if err := blockbook.call(ctx, path.Join("sendtx", hexutil.Encode(encodedTx)), params, &result); err != nil {
149+
blockbook.log.Errorf("Failed to send transaction: %v", err)
150+
return errp.WithStack(err)
151+
}
152+
153+
if result.Error.Message != "" {
154+
blockbook.log.Errorf("Error sending transaction: %s", result.Error.Message)
155+
return errp.Newf("error sending transaction: %s", result.Error.Message)
156+
}
157+
158+
blockbook.log.Infof("Transaction sent: %s", result.Txid)
159+
return nil
133160
}
134161

135162
// ERC20Balance implements rpc.Interface.

0 commit comments

Comments
 (0)