-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverifytx_test.go
136 lines (103 loc) · 11.1 KB
/
verifytx_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
package gobtcsign
import (
"testing"
"github.com/btcsuite/btcd/chaincfg"
"github.com/stretchr/testify/require"
"github.com/yyle88/gobtcsign/dogecoin"
)
func TestVerifyTx_BTC_testnet(t *testing.T) {
const txHex = "0200000001eb3baa8db3e0d9beb57b068e81c568f788ceded45969e5c14a9305cb498918f6010000006b483045022100daaf65f80aec73bf392eac919cef20972f4f6ff18eff5fdda85d50323ce4d24702202796de2b2cf6467d675841152ba55d039c99c91ffa088e628d720c3815b4a4f50121032ddc21efb4892087d1514725bf284dc7c778ed444591c85d10ca65e17831407bffffffff0200e1f505000000001976a91454c298801975f291b82bc0226a536e5dfc50487688acc8c52475100000001976a91493229ffd649ce4d48081239f52e68a508e76fea588ac00000000"
msgTx, err := NewMsgTxFromHex(txHex)
require.NoError(t, err)
t.Log(msgTx.TxHash().String()) //这个发送者是 P2PKH 的,在BTC系统中虽然 P2WPKH 更推荐但是 P2PKH 也是很常见的
require.NoError(t, VerifySignV2(msgTx, []*VerifyTxInputParam{
NewVerifyTxInputParam("mtvw738RMLYhgKLShmjK5arHv9NmJSWZ8D", 70784889640), //P2PKH 签名不将 amount 包含在生成的签名哈希中,因此也不验证它,随便填都行
}, &chaincfg.TestNet3Params))
}
func TestVerifyTx_BTC_testnet_2(t *testing.T) {
const txHex = "0100000001e8a3a8efffc49d21a3a8f4fd7ea908bd10f8402d4bd160fe3aa5874b29bfb3eb010000006b483045022100a9291cc859097aea9c596143f47afc5ae9d60c47e9e32c6ad2532991699f7778022052af39a9bef4f6b968ae5ed254e453a9b789d583cd47ec53e52a07e1dda57b9f0121025032650be6df92d073742483f180b40ab2c245272b8178df8e7e4e49de34e393ffffffff02cf035b00000000001976a9144daa545eb4613d36b34f70ea4f048ceef50e030688ac5699c902010000001976a914fff8e8b57e3b4360af2da5a8f08d1c4133e6998b88ac00000000"
msgTx, err := NewMsgTxFromHex(txHex)
require.NoError(t, err)
t.Log(msgTx.TxHash().String()) //这个发送者也是 P2PKH 的
require.NoError(t, VerifySignV2(msgTx, []*VerifyTxInputParam{
NewVerifyTxInputParam("n4rQnUNCiBR6mhFFgtzJaMjssDo6QohTEh", 4347958369), //P2PKH 签名不将 amount 包含在生成的签名哈希中,因此也不验证它,随便填都行
}, &chaincfg.TestNet3Params))
}
func TestVerifyTx_BTC_testnet_3(t *testing.T) {
const txHex = "0100000001b446b59b1580baba0de2c4b2ce2157c77579204836c29ee96f027aaecf9b14d3010000006b483045022100eff1a651289dc5c5fb0607bd30035d0c6a13c1ffbae386203f5e01771fc984cb02203bd3daea947847b89663c534ca540788ba5b55bd8f04517388682f75355c74d30121025032650be6df92d073742483f180b40ab2c245272b8178df8e7e4e49de34e393ffffffff02cf035b00000000001976a914c28671985556aaf0604d4d8b8d9fdfe20d5a850e88acb7226b02010000001976a914fff8e8b57e3b4360af2da5a8f08d1c4133e6998b88ac00000000"
msgTx, err := NewMsgTxFromHex(txHex)
require.NoError(t, err)
t.Log(msgTx.TxHash().String()) //这个发送者还是 P2PKH 的
require.NoError(t, VerifySignV2(msgTx, []*VerifyTxInputParam{
NewVerifyTxInputParam("n4rQnUNCiBR6mhFFgtzJaMjssDo6QohTEh", 4341733718), //P2PKH 签名不将 amount 包含在生成的签名哈希中,因此也不验证它,随便填都行
}, &chaincfg.TestNet3Params))
}
func TestVerifyTx_BTC_testnet_4(t *testing.T) {
const txHex = "0100000000010528630cf5b53c792f5dae8eae23993ca6ad2f18376fe84bcb344abd1040cc87fb0000000000fdffffff39b4a03ab0fab33ca3a65275314ec326d300a2033fd946ab947621f0d789c8fc0100000000fdffffff7db9e66f7c3a6f6f3fe704c1fed83f57768adab4d2682165a31e27bb1b43985c0000000000fdffffff48934f379bdfa15e33ac80c8fde5fe000e149692d8fe9614cc41cb056148e75f0300000000fdffffff526a9d249f275f3c45a67f145991f33cfa9303421e15d71802df935727c78ade0100000000fdffffff03b80b000000000000160014b3c4715e00a5ff9707ec7be2586e62d286ae4a18d007000000000000160014fcb55e6920e2c6f37327a5bf4a24cf42ebbaf07c213300000000000016001462152b40d8b2cbac358541d850c079ea10d1407f0247304402201977b7da04ca36eb2b7cb3334b7f0f6551733ee02097c672f24938766b47778e02202bc7b30a01b55748f408f35a666376ee23695490d349cde54fee7a00bf5e6926012102407ea64d7a9e992028a94481af95ea7d8f54870bd73e5878a014da594335ba3202483045022100d06785151683bf48e2327194ba0a09090e76d9e7f1d1d2f67c69b693c3663127022001f553f91afc9820507c32f1a0197719df2312e51a80fc3d517efcc2bc14168c012102407ea64d7a9e992028a94481af95ea7d8f54870bd73e5878a014da594335ba3202483045022100f7aee523be19affa0548dcd3f74352088da60d2630a4cbac55f81757a5de112f02203e9a09a2b90df4ab61a440a3b72b4448a250289c0680db992ade9080a19cdc44012102407ea64d7a9e992028a94481af95ea7d8f54870bd73e5878a014da594335ba3202473044022079092a4916cac06227c914df0baeca915f2f5f7c62983287a8238f933fc47f70022008140a0e7f1353461ad471a17aa405f8ba18bc028772896d61914b6d2bec6444012102407ea64d7a9e992028a94481af95ea7d8f54870bd73e5878a014da594335ba320247304402205396b130a34f9bd361cc9b150b3053a31b8225234685f5585729e26f1ddd4c540220349d16280aec9e1ca8d18a556f5e9cb740f18362d36337bc81c3d23cf8ff3b1c012102407ea64d7a9e992028a94481af95ea7d8f54870bd73e5878a014da594335ba3200000000"
msgTx, err := NewMsgTxFromHex(txHex)
require.NoError(t, err)
t.Log(msgTx.TxHash().String()) //这个是 P2WPKH 的
require.NoError(t, VerifySignV2(msgTx, []*VerifyTxInputParam{
NewVerifyTxInputParam("tb1qvg2jksxckt96cdv9g8v9psreaggdzsrlm6arap", 4900), //当发送者是 P2WPKH 时,就需要检查数量,因此必须设置正确
NewVerifyTxInputParam("tb1qvg2jksxckt96cdv9g8v9psreaggdzsrlm6arap", 4320), //当发送者是 P2WPKH 时,就需要检查数量,因此必须设置正确
NewVerifyTxInputParam("tb1qvg2jksxckt96cdv9g8v9psreaggdzsrlm6arap", 4560), //当发送者是 P2WPKH 时,就需要检查数量,因此必须设置正确
NewVerifyTxInputParam("tb1qvg2jksxckt96cdv9g8v9psreaggdzsrlm6arap", 4900), //当发送者是 P2WPKH 时,就需要检查数量,因此必须设置正确
NewVerifyTxInputParam("tb1qvg2jksxckt96cdv9g8v9psreaggdzsrlm6arap", 22865), //当发送者是 P2WPKH 时,就需要检查数量,因此必须设置正确
}, &chaincfg.TestNet3Params))
}
func TestVerifyTx_BTC_testnet_5(t *testing.T) {
const txHex = "010000000001011939727ec645869768167683487829f437cc37c664938345426d0df14e5df0e10200000000fdffffff02d204000000000000160014b3c4715e00a5ff9707ec7be2586e62d286ae4a18e80200000000000016001462152b40d8b2cbac358541d850c079ea10d1407f02483045022100e8269080acc14fd24ee13cbbdaa5ea34192f090c917b4ca3da44eda25badd58e02206813da9023bebd556a95e04e6a55c9a5fdf5dfb19746c896d7fd7f26aaa58878012102407ea64d7a9e992028a94481af95ea7d8f54870bd73e5878a014da594335ba3200000000"
msgTx, err := NewMsgTxFromHex(txHex)
require.NoError(t, err)
t.Log(msgTx.TxHash().String()) //这个是 P2WPKH 的,因为 P2WPKH 的用例有点少了这里再补充个新的
require.NoError(t, VerifySignV2(msgTx, []*VerifyTxInputParam{
NewVerifyTxInputParam("tb1qvg2jksxckt96cdv9g8v9psreaggdzsrlm6arap", 13089), //当发送者是 P2WPKH 时,就需要检查数量,因此必须设置正确
}, &chaincfg.TestNet3Params))
}
func TestVerifyTx_DOGE_testnet(t *testing.T) {
const txHex = "0100000001d7c8f1b28cab162a517889c2d66f9194446cdc3a571bd7f8ffdbc15b16a0970a000000006b483045022100bba2e1fd90d763d77775f7b4488841846fa307c3b203355048694ae1f048027d0220191e32dc86ad41536b93791b6070bcedd2488dc2c8445572b018424cf9cb91c90121031c983815f246c81e22e824901143c407560047227394d8c39fc754d45fec2770fdffffff0280969800000000001976a914b92052765b0007a3e3f0375b34430d7e8df695ea88acf135f503000000001976a91496c179f468add293a9cfaebc127a62d09bcb57c288ac00000000"
msgTx, err := NewMsgTxFromHex(txHex)
require.NoError(t, err)
t.Log(msgTx.TxHash().String())
netParams := &dogecoin.TestNetParams
require.NoError(t, VerifySignV2(msgTx, []*VerifyTxInputParam{
NewVerifyTxInputParam("nhwHQ29uEKnHeiWNLpU2zVHtcrZjaLKaHF", 0), //P2PKH 签名不将 amount 包含在生成的签名哈希中,因此也不验证它,随便填都行
}, netParams))
}
func TestVerifyTx_DOGE_mainnet(t *testing.T) {
const txHex = "01000000019cd6fd32cca16c3745ffe3d4a952ae7463df930f899f1b52424dffb4932d6fdb010000006a473044022013dbb0fe1678ae1f74fa3f861456f5b0396211b1866d202242d0c4becd48429e02202b0e55c020f8f2c05a40b192fd1c3ea20fe8f6299bbbf9bf87a41d14c62067200121023c3520f4835bb87b9580bbdc6cd364072b45167c774c4556c15c580cc5fcba7bffffffff02a0862d46010000001976a914df20bc04fd348aa2e7399d677de8a3eb742bb27488ac38e5f46bf30a00001976a9141303e3c789d3b835d95c8b6be590ad15af23c90b88ac00000000"
msgTx, err := NewMsgTxFromHex(txHex)
require.NoError(t, err)
t.Log(msgTx.TxHash().String())
netParams := &dogecoin.MainNetParams
require.NoError(t, VerifySignV2(msgTx, []*VerifyTxInputParam{
NewVerifyTxInputParam("D6se3Ajq9mF8YD4p7jSXwZxewT6ePsnea6", 0), //P2PKH 签名不将 amount 包含在生成的签名哈希中,因此也不验证它,随便填都行
}, netParams))
}
func TestVerifyTx_DOGE_mainnet_2(t *testing.T) {
const txHex = "0100000003ecd4d9d0bfa4d2126d08d17686b069d0a36901b5650023d02c86dd0ad6b92264000000006a473044022072d8fb163976d8aebad8e413e0cc958022a0b481f5d4db3a5d111a5ef00cc63802200f25c83f9f44425799a9ca86e992a994ff2db8c0f0e80523c0dd4753fd13fff601210338a2c85b6cf704e6b2eab54c985b78f7aacde132082d4ff5c0d62d3cd08da6a4ffffffff8f6e68ae9eab24647ce54b9e275b2a8bef25f2865440b34358388720ad2ad073010000006b483045022100e8d2eec625ca70c98e2043cae9232420eed0cc2166e4bcebe53debfe8064306f02207740703a9cfeb7967dd2e8c62fb7957fe599a0bf91998623d96e85df50e0dfa0012102cc9c56c656f549e5f88dcf3a9d1bc54e6638cfe69b379f6d41a5d1f756376ca4ffffffff23da7350f40dfd635284552202fcb801289afa2d906a5af6ca33f1e02ffccf48060000006b483045022100cf5b201fd538c76f8a82ccbc19c04d975cee249fbe24c49e27fa0ad78e86a5c302200723c0e5b0f66d81b40aec6892462700a845d9490d40b2d91ff1f4a51c97312e012102e272a9019a284d1e1db8adada953b4bb2b2eebc9264e45b3886a5acdb6f7b049ffffffff0294d7ca41000000001976a914551137476a06cfdedd91279f60692682b3f3d68b88ac043b10ce7be60a001976a9140be4c25349ee33a3f3d9674fdd31618918cacd4588ac00000000"
msgTx, err := NewMsgTxFromHex(txHex)
require.NoError(t, err)
t.Log(msgTx.TxHash().String())
// 请看这里 https://sochain.com/tx/DOGE/aa9188f81b8114314318bd75fab275f40022ff1e2a83ea2c84b809ef2d562a29
// 你需要做的就是把看到的 inputs 拷贝下来
var addresses = []string{
"DCYWbjW1rRyWnXSKnjp8tuQYUPsv9Yj1cT",
"D8guyBsLjbLgnXQBsxtDgnbtwAh662aJGb",
"DJnqNZJn21HKJjEzjLTTWToBpvZPjomTnR",
}
require.NoError(t, VerifyP2PKHSign(msgTx, addresses, &dogecoin.MainNetParams))
}
func TestVerifyTx_DOGE_mainnet_3(t *testing.T) {
const txHex = "0100000002d2b3941020b7a48057bc8fbab13f45f681e1717ddadab6b83ac2dbd926cb914d000000006a473044022021a6ad19b23b1dc0be9914d8fd49af932f59e26f0a113ba225083199dc1afa9002206a6489794429bd86c90849d03b54230203500c45bd3532000d8c0c97cacbc433012103e2c5018631f5960a9c0c988d7b5355048bb8ff2a772c69a59167208f1a2a9896ffffffffe72683d7ed5c5cc9918823031131ad572e9b190c5ced1008a57838f952a77ce2010000006a47304402205c3447fda59028ff08f10809b6003af7d94ba84d52280d6362acaca8fbd752a8022060d40242de21b2dfd3a6ac0b6d0b37799b53721d69fb90c9e461c30ac9585221012103e2c5018631f5960a9c0c988d7b5355048bb8ff2a772c69a59167208f1a2a9896ffffffff0200e9587278e60a001976a91451368824f9f5badcf889c024331cc45d2087558a88ac80439bd0b56f00001976a914869d6c848672f73fcb6b357b5650e780bad2106988ac00000000"
msgTx, err := NewMsgTxFromHex(txHex)
require.NoError(t, err)
t.Log(msgTx.TxHash().String())
//请看这里 https://www.oklink.com/zh-hans/doge/tx/6422b9d60add862cd0230065b50169a3d069b08676d1086d12d2a4bfd0d9d4ec
//你需要做的就是把 输入列表 拷贝下来
var addresses = []string{
"DHQsfy66JsYSnwjCABFN6NNqW4kHQe63oU",
"DHQsfy66JsYSnwjCABFN6NNqW4kHQe63oU",
}
require.NoError(t, VerifyP2PKHSign(msgTx, addresses, &dogecoin.MainNetParams))
}