-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendtx.go
48 lines (42 loc) · 1.14 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
package colx
import (
"bytes"
"encoding/hex"
"github.com/weijun-sh/gethscan-server/log"
"github.com/weijun-sh/gethscan-server/tokens"
"github.com/giangnamnabka/btcwallet/wallet/txauthor"
)
// SendTransaction send signed tx
func (b *Bridge) SendTransaction(signedTx interface{}) (txHash string, err error) {
authoredTx, ok := signedTx.(*txauthor.AuthoredTx)
if !ok {
return "", tokens.ErrWrongRawTx
}
tx := authoredTx.Tx
if tx == nil {
return "", tokens.ErrWrongRawTx
}
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
err = tx.Serialize(buf)
if err != nil {
return "", err
}
txHex := hex.EncodeToString(buf.Bytes())
log.Info("Bridge send tx", "hash", tx.TxHash())
txHash, err = b.PostTransaction(txHex)
if err == nil {
for _, txin := range tx.TxIn {
inputtxhash := txin.PreviousOutPoint.Hash.String()
inputvout := int(txin.PreviousOutPoint.Index)
cond := func() bool {
status, getstatuserr := b.GetElectTransactionStatus(txHash)
if getstatuserr == nil && *status.Confirmed {
return true
}
return false
}
_ = b.SetUnlockUtxoCond(inputtxhash, inputvout, cond)
}
}
return txHash, err
}