-
Notifications
You must be signed in to change notification settings - Fork 7
/
WaykiDexCancelTx.go
60 lines (51 loc) · 1.42 KB
/
WaykiDexCancelTx.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
package commons
import (
"bytes"
"encoding/hex"
"github.com/btcsuite/btcutil"
hash2 "github.com/WaykiChain/wicc-wallet-utils-go/commons/hash"
)
type WaykiDexCancelTx struct {
WaykiBaseSignTx
Fees uint64
FeeSymbol string //Fee Type (WICC/WUSD)
DexHash []byte //From Coin Type
}
func (tx WaykiDexCancelTx) SignTx(wifKey *btcutil.WIF) string {
buf := bytes.NewBuffer([]byte{})
writer := NewWriterHelper(buf)
writer.WriteByte(byte(tx.TxType))
writer.WriteVarInt(tx.Version)
writer.WriteVarInt(tx.ValidHeight)
if(tx.UserId!=nil){
writer.WriteUserId(tx.UserId)
}else if(tx.PubKey!=nil){
writer.WritePubKeyId(tx.PubKey)
}
writer.WriteString(tx.FeeSymbol)
writer.WriteVarInt(int64(tx.Fees))
writer.WriteReverse(tx.DexHash)
signedBytes := tx.doSignTx(wifKey)
writer.WriteBytes(signedBytes)
rawTx := hex.EncodeToString(buf.Bytes())
return rawTx
}
func (tx WaykiDexCancelTx) doSignTx(wifKey *btcutil.WIF) []byte {
buf := bytes.NewBuffer([]byte{})
writer := NewWriterHelper(buf)
writer.WriteVarInt(tx.Version)
writer.WriteByte(byte(tx.TxType))
writer.WriteVarInt(tx.ValidHeight)
if(tx.UserId!=nil){
writer.WriteUserId(tx.UserId)
}else if(tx.PubKey!=nil){
writer.WritePubKeyId(tx.PubKey)
}
writer.WriteString(tx.FeeSymbol)
writer.WriteVarInt(int64(tx.Fees))
writer.WriteReverse(tx.DexHash)
hash := hash2.DoubleHash256(buf.Bytes())
key := wifKey.PrivKey
ss, _ := key.Sign(hash)
return ss.Serialize()
}