-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction_test.go
235 lines (198 loc) · 6.8 KB
/
transaction_test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package btcadaptor
import (
"encoding/hex"
"encoding/json"
"fmt"
"testing"
"github.com/palletone/adaptor"
)
func TestCreateTransferTokenTx(t *testing.T) {
//rpcParams := RPCParams{
// Host: "localhost:18334",
// RPCUser: "test",
// RPCPasswd: "123456",
// CertPath: GCertPath,
//}
rpcParams := RPCParams{
Host: "123.126.106.86:28556",
RPCUser: "pallettest",
RPCPasswd: "pallet123456",
CertPath: "./rpc-123.126.106.86-testnet.cert",
}
//
var input adaptor.CreateTransferTokenTxInput
input.FromAddress = "mgtT62nq65DsPPAzPp6KhsWoHjNQUR9Bu5" //2N4jXJyMo8eRKLPWqi5iykAyFLXd6szehwA
input.ToAddress = "2N4jXJyMo8eRKLPWqi5iykAyFLXd6szehwA" //mgtT62nq65DsPPAzPp6KhsWoHjNQUR9Bu5
input.Amount = adaptor.NewAmountAssetString("980000", "BTC") //dao, 0.0099 btc
input.Fee = adaptor.NewAmountAssetString("10000", "BTC") //dao,0.0001 btc
//input.Extra
input.ToAddress = "PalletOne"
input.ToAddress = "P19z4r7G9MpZtaYMZcATWinTwXeGBj7fWTd"
input.Amount = adaptor.NewAmountAssetString("0", "BTC") //op_return
//idIndex, _ := hex.DecodeString("101d482b60cd3f74a61ce265d62e383456b9c21c84477931d207ea8f503d84cc01")
//input.Extra = append(input.Extra, idIndex...)
//{"transaction":"AQAAAAHMhD1Qj+oH0jF5R4QcwrlWNDgu1mXiHKZ0P81gK0gdEAEAAAAAAAAAAAJAQg8AAAAAABl2qRS93Jpi6bfDz9vhyBdSDiTjLDOfMoisQEIPAAAAAAAZdqkUDwjlW8/CB2MtLc/D1NtLbY2Rsi6IrAAAAAA=","extra":"EB1IK2DNP3SmHOJl1i44NFa5whyER3kx0gfqj1A9hMwB"}
output, err := CreateTransferTokenTx(&input, &rpcParams, NETID_TEST)
if err != nil {
fmt.Println(err.Error())
} else {
resultJSON, _ := json.Marshal(output)
fmt.Println(string(resultJSON))
fmt.Printf("Extra : %x\n", output.Extra)
rawTxHex := fmt.Sprintf("%x", output.Transaction)
fmt.Printf("rawTxHex : %s\n", rawTxHex)
_, err = decodeRawTransaction(rawTxHex, NETID_TEST)
if err != nil {
fmt.Println(err.Error())
}
}
}
func TestCalcTxHash(t *testing.T) {
tx, _ := hex.DecodeString("010000000144080d1b48b02a483b5341ba70b2660616d72d1aeb006518f3e261f7f651e48d00000000fdfd00004730440220475bc769dd39d5820131c3e3527f6710886c6852e66635b1f68aff0fdad88f5702206ce2ca0ac655f74ec5f01c0ca2ae9bc1228176bab1855a0a053c0c177bb5ae7c01483045022100dfa8811cee744502d183f67e8166480b0bcb1f0d4259f6fe3b2ee16aa0be568a022079aedff69da83654fe15bb0ab927510c737f772d1d048c219c25546d76af73eb014c69522103940ab29fbf214da2d8ec99c47db63879957311bd90d2f1c635828604d541051421020106ca23b4f28dbc83838ee4745accf90e5621fe70df5b1ee8f7e1b3b41b64cb21029d80ff37838e4989a6aa26af41149d4f671976329e9ddb9b78fdea9814ae6ef553ae000000000250c30000000000001976a9140f08e55bcfc207632d2dcfc3d4db4b6d8d91b22e88acf07e0e000000000017a9147e037d8b8093a7cf3a6ec83aa8c852761a5d0cce8700000000")
input := &adaptor.CalcTxHashInput{Transaction: tx}
output, err := CalcTxHash(input)
if err != nil {
fmt.Println(err.Error())
} else {
resultJSON, _ := json.Marshal(output)
fmt.Println(string(resultJSON))
fmt.Printf("%x\n", output.Hash)
}
}
func TestGetBlockInfo(t *testing.T) {
//rpcParams := RPCParams{
// Host: "localhost:18334",
// RPCUser: "test",
// RPCPasswd: "123456",
// CertPath: GCertPath,
//}
rpcParams := RPCParams{
Host: "123.126.106.86:28556",
RPCUser: "pallettest",
RPCPasswd: "pallet123456",
CertPath: "./rpc-123.126.106.86-testnet.cert",
}
var input adaptor.GetBlockInfoInput
input.Latest = true
blkIDHex := "0000000094305b3c6173d333a9c9732a7b3af7534fade0fbdff95d932c3b1a94"
blkID, _ := hex.DecodeString(blkIDHex)
input.BlockID = blkID
fmt.Printf("%x\n", input.BlockID)
input.Height = 1
output, err := GetBlockInfo(&input, &rpcParams)
if err != nil {
fmt.Println(err.Error())
} else {
resultJSON, _ := json.Marshal(output)
fmt.Println(string(resultJSON))
}
}
func TestGetPalletOneMappingAddress(t *testing.T) {
//rpcParams := RPCParams{
// Host: "localhost:18334",
// RPCUser: "test",
// RPCPasswd: "123456",
// CertPath: GCertPath,
//}
rpcParams := RPCParams{
Host: "123.126.106.86:28556",
RPCUser: "pallettest",
RPCPasswd: "pallet123456",
CertPath: "./rpc-123.126.106.86-testnet.cert",
}
//txIDStr := "8b886fb5033d26c2bad728d73188e4eac46e2eb61260a2638b3330484498c576"
//txIDByte, _ := hex.DecodeString(txIDStr)
//
//index := 128
//str := fmt.Sprintf("%x", index)
//fmt.Println(str)
//indexByte, _ := hex.DecodeString(str)
//fmt.Println(indexByte)
//
//fmt.Printf("%x\n", txIDByte)
//txIDByte = append(txIDByte, indexByte[0])
//fmt.Printf("%x\n", txIDByte)
//
//n := uint64(txIDByte[len(txIDByte)-1])
//fmt.Println(n)
//return
txIDHex := "6b2c4379b326757dd5b847f3c584170c5fe2649e6e33f962cf7e9826f77f07b6"
var input adaptor.GetPalletOneMappingAddressInput
input.MappingDataSource = txIDHex
output, err := GetPalletOneMappingAddress(&input, &rpcParams)
if err != nil {
fmt.Println(err.Error())
} else {
resultJSON, _ := json.Marshal(output)
fmt.Println(string(resultJSON))
}
}
func TestGetTxBasicInfo(t *testing.T) {
//rpcParams := RPCParams{
// Host: "localhost:18334",
// RPCUser: "test",
// RPCPasswd: "123456",
// CertPath: GCertPath,
//}
rpcParams := RPCParams{
Host: "123.126.106.86:28556",
RPCUser: "pallettest",
RPCPasswd: "pallet123456",
CertPath: "./rpc-123.126.106.86-testnet.cert",
}
txIDHex := "8b886fb5033d26c2bad728d73188e4eac46e2eb61260a2638b3330484498c576"
txID, _ := hex.DecodeString(txIDHex)
var input adaptor.GetTxBasicInfoInput
input.TxID = txID
fmt.Printf("%x\n", input.TxID)
output, err := GetTxBasicInfo(&input, &rpcParams)
if err != nil {
fmt.Println(err.Error())
} else {
resultJSON, _ := json.Marshal(output)
fmt.Println(string(resultJSON))
}
}
func TestGetTransferTx(t *testing.T) {
//rpcParams := RPCParams{
// Host: "localhost:18334",
// RPCUser: "test",
// RPCPasswd: "123456",
// CertPath: GCertPath,
//}
rpcParams := RPCParams{
Host: "123.126.106.86:28556",
RPCUser: "pallettest",
RPCPasswd: "pallet123456",
CertPath: "./rpc-123.126.106.86-testnet.cert",
}
txIDHex := "52dab174e0d719704316c9301f146e1e90e7797ec8fe9f357a5fdfb0a62a1ab4"
txID, _ := hex.DecodeString(txIDHex)
var input adaptor.GetTransferTxInput
input.TxID = txID
fmt.Printf("%x\n", input.TxID)
output, err := GetTransferTx(&input, &rpcParams)
if err != nil {
fmt.Println(err.Error())
} else {
resultJSON, _ := json.Marshal(output)
fmt.Println(string(resultJSON))
if 0 != len(output.Tx.AttachData) {
fmt.Println("data : ", string(output.Tx.AttachData))
}
}
}
func TestGetTxBasicInfoHttp(t *testing.T) {
txIDHex := "8b886fb5033d26c2bad728d73188e4eac46e2eb61260a2638b3330484498c576"
txID, _ := hex.DecodeString(txIDHex)
var input adaptor.GetTxBasicInfoInput
input.TxID = txID
fmt.Printf("%x\n", input.TxID)
output, err := GetTxBasicInfoHttp(&input, NETID_TEST)
if err != nil {
fmt.Println(err.Error())
} else {
resultJSON, _ := json.Marshal(output)
fmt.Println(string(resultJSON))
}
}