-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendtx.go
36 lines (33 loc) · 925 Bytes
/
sendtx.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
package cosmos
import (
"encoding/json"
"errors"
"fmt"
"github.com/deltaswapio/swaprouter/v3/tokens"
)
// SendTransaction send signed tx
func (b *Bridge) SendTransaction(signedTx interface{}) (string, error) {
if txBytes, ok := signedTx.([]byte); !ok {
return "", errors.New("wrong signed transaction type")
} else {
req := &BroadcastTxRequest{
TxBytes: string(txBytes),
Mode: "BROADCAST_MODE_SYNC",
}
if txRes, err := b.BroadcastTx(req); err != nil {
return "", err
} else {
if txRes == "" {
return "", tokens.ErrBroadcastTx
}
var txResponse *BroadcastTxResponse
if err := json.Unmarshal([]byte(txRes), &txResponse); err != nil {
return "", err
}
if txResponse.TxResponse.Code != 0 && txResponse.TxResponse.Code != 19 {
return "", fmt.Errorf("SendTransaction error, code: %v", txResponse.TxResponse.Code)
}
return txResponse.TxResponse.TxHash, nil
}
}
}