diff --git a/bchain/baseparser.go b/bchain/baseparser.go index d18da3b4..abe665b4 100644 --- a/bchain/baseparser.go +++ b/bchain/baseparser.go @@ -170,8 +170,9 @@ func (p *BaseParser) PackTx(tx *Tx, height uint32, blockTime int64) ([]byte, err if err != nil { return nil, errors.Annotatef(err, "Vin %v Hex %v", i, vi.ScriptSig.Hex) } + // coinbase txs do not have Vin.txid itxid, err := p.PackTxid(vi.Txid) - if err != nil { + if err != nil && err != ErrTxidMissing { return nil, errors.Annotatef(err, "Vin %v Txid %v", i, vi.Txid) } pti[i] = &ProtoTransaction_VinType{ diff --git a/bchain/coins/dash/dashparser_test.go b/bchain/coins/dash/dashparser_test.go index 0a373fce..cdab85ba 100644 --- a/bchain/coins/dash/dashparser_test.go +++ b/bchain/coins/dash/dashparser_test.go @@ -1,4 +1,4 @@ -// +build unittest +// build unittest package dash @@ -159,6 +159,42 @@ var ( }, } testTxPacked1 = "0a20ed732a404cdfd4e0475a7a016200b7eef191f2c9de0ffdef8a20091c0499299c12e2010100000001f85264d11a747bdba77d411e5e4a3d35e3aeb5843b34a95234a2121ac65496bd000000006b483045022100dfa158fbd9773fab4f6f329c807e040af0c3a40967cbe01667169b914ed5ad960220061c5876364caa3e3c9c990ad2b4cc8b1a53d4f954dbda8434b0e67cc8348ff6012103093865e1e132b33a2a5ed01c79d2edba3473826a66cb26b8311bfa42749c2190ffffffff02ec3f8a2a010000001976a91470dcef2a22575d7a8f0779fb1d6cdd48135bd22788ac3116491d000000001976a91471348f7780e955a2a60eba17ecc4c826ebc23a9888ac0000000018f6cad8e305200028c0e03e3299010a001220bd9654c61a12a23452a9343b84b5aee3353d4a5e1e417da7db7b741ad16452f81800226b483045022100dfa158fbd9773fab4f6f329c807e040af0c3a40967cbe01667169b914ed5ad960220061c5876364caa3e3c9c990ad2b4cc8b1a53d4f954dbda8434b0e67cc8348ff6012103093865e1e132b33a2a5ed01c79d2edba3473826a66cb26b8311bfa42749c219028ffffffff0f3a480a05012a8a3fec10001a1976a91470dcef2a22575d7a8f0779fb1d6cdd48135bd22788ac2222586b7963425831796b565858733932704169365a51775a50457265396b5348484b483a470a041d49163110011a1976a91471348f7780e955a2a60eba17ecc4c826ebc23a9888ac2222586d31523974684b426d32455a4b5a657658736d4d5834445677515175546f685a754001" + + testTx2 = bchain.Tx{ + Blocktime: 1551246710, + Confirmations: 0, + Hex: "03000500010000000000000000000000000000000000000000000000000000000000000000ffffffff170340b00f1291af3c09542bc8349901000000002f4e614effffffff024181f809000000001976a9146a341485a9444b35dc9cb90d24e7483de7d37e0088ac3581f809000000001976a9140d1156f6026bf975ea3553b03fb534d0959c294c88ac0000000026010040b00f000000000000000000000000000000000000000000000000000000000000000000", + LockTime: 0, + Time: 1551246710, + Txid: "71d6975e3b79b52baf26c3269896a34f3bedfb04561c692ffa31f64dada1f9c4", + Version: 3, + Vin: []bchain.Vin{ + { + Coinbase: "0340b00f1291af3c09542bc8349901000000002f4e614e", + Sequence: 4294967295, + }, + }, + Vout: []bchain.Vout{ + { + N: 0, + ScriptPubKey: bchain.ScriptPubKey{ + Addresses: []string{"XkNPrBSJtrHZUvUqb3JF4g5rMB3uzaJfEL"}, + Hex: "76a9146a341485a9444b35dc9cb90d24e7483de7d37e0088ac", + }, + ValueSat: *big.NewInt(167280961), + }, + { + N: 1, + ScriptPubKey: bchain.ScriptPubKey{ + Addresses: []string{"XbswPXhcLqm5AN5gwcTTyiUGSP2YndWwk9"}, + Hex: "76a9140d1156f6026bf975ea3553b03fb534d0959c294c88ac", + }, + ValueSat: *big.NewInt(167280949), + }, + }, + } + + testTxPacked2 = "0a2071d6975e3b79b52baf26c3269896a34f3bedfb04561c692ffa31f64dada1f9c412b50103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff170340b00f1291af3c09542bc8349901000000002f4e614effffffff024181f809000000001976a9146a341485a9444b35dc9cb90d24e7483de7d37e0088ac3581f809000000001976a9140d1156f6026bf975ea3553b03fb534d0959c294c88ac0000000026010040b00f00000000000000000000000000000000000000000000000000000000000000000018f6cad8e305200028c0e03e32380a2e30333430623030663132393161663363303935343262633833343939303130303030303030303266346536313465180028ffffffff0f3a470a0409f8814110001a1976a9146a341485a9444b35dc9cb90d24e7483de7d37e0088ac2222586b4e507242534a7472485a5576557162334a46346735724d4233757a614a66454c3a470a0409f8813510011a1976a9140d1156f6026bf975ea3553b03fb534d0959c294c88ac222258627377505868634c716d35414e35677763545479695547535032596e6457776b394003" ) func TestBaseParser_ParseTxFromJson(t *testing.T) { @@ -176,41 +212,10 @@ func TestBaseParser_ParseTxFromJson(t *testing.T) { }, { name: "special tx - DIP2", - msg: `{"hex":"03000500010000000000000000000000000000000000000000000000000000000000000000ffffffff170340b00f1291af3c09542bc8349901000000002f4e614effffffff024181f809000000001976a9146a341485a9444b35dc9cb90d24e7483de7d37e0088ac3581f809000000001976a9140d1156f6026bf975ea3553b03fb534d0959c294c88ac0000000026010040b00f000000000000000000000000000000000000000000000000000000000000000000","txid":"71d6975e3b79b52baf26c3269896a34f3bedfb04561c692ffa31f64dada1f9c4","size":181,"version":3,"type":5,"locktime":0,"vin":[{"coinbase":"0340b00f1291af3c09542bc8349901000000002f4e614e","sequence":4294967295}],"vout":[{"value":1.67280961,"valueSat":167280961,"n":0,"scriptPubKey":{"asm":"OP_DUPOP_HASH1606a341485a9444b35dc9cb90d24e7483de7d37e00OP_EQUALVERIFYOP_CHECKSIG","hex":"76a9146a341485a9444b35dc9cb90d24e7483de7d37e0088ac","reqSigs":1,"type":"pubkeyhash","addresses":["XkNPrBSJtrHZUvUqb3JF4g5rMB3uzaJfEL"]}},{"value":1.67280949,"valueSat":167280949,"n":1,"scriptPubKey":{"asm":"OP_DUPOP_HASH1600d1156f6026bf975ea3553b03fb534d0959c294cOP_EQUALVERIFYOP_CHECKSIG","hex":"76a9140d1156f6026bf975ea3553b03fb534d0959c294c88ac","reqSigs":1,"type":"pubkeyhash","addresses":["XbswPXhcLqm5AN5gwcTTyiUGSP2YndWwk9"]}}],"extraPayloadSize":38,"extraPayload":"010040b00f000000000000000000000000000000000000000000000000000000000000000000","cbTx":{"version":1,"height":1028160,"merkleRootMNList":"0000000000000000000000000000000000000000000000000000000000000000"},"blockhash":"000000000000002099caaf1a877911d99a5980ede9b981280eecb291afedf87b","height":1028160,"confirmations":140,"time":1551246710,"blocktime":1551246710,"instantlock":false}`, - want: &bchain.Tx{ - Blocktime: 1551246710, - Confirmations: 140, - Hex: "03000500010000000000000000000000000000000000000000000000000000000000000000ffffffff170340b00f1291af3c09542bc8349901000000002f4e614effffffff024181f809000000001976a9146a341485a9444b35dc9cb90d24e7483de7d37e0088ac3581f809000000001976a9140d1156f6026bf975ea3553b03fb534d0959c294c88ac0000000026010040b00f000000000000000000000000000000000000000000000000000000000000000000", - LockTime: 0, - Time: 1551246710, - Txid: "71d6975e3b79b52baf26c3269896a34f3bedfb04561c692ffa31f64dada1f9c4", - Version: 3, - Vin: []bchain.Vin{ - { - Coinbase: "0340b00f1291af3c09542bc8349901000000002f4e614e", - Sequence: 4294967295, - }, - }, - Vout: []bchain.Vout{ - { - N: 0, - ScriptPubKey: bchain.ScriptPubKey{ - Addresses: []string{"XkNPrBSJtrHZUvUqb3JF4g5rMB3uzaJfEL"}, - Hex: "76a9146a341485a9444b35dc9cb90d24e7483de7d37e0088ac", - }, - ValueSat: *big.NewInt(167280961), - }, - { - N: 1, - ScriptPubKey: bchain.ScriptPubKey{ - Addresses: []string{"XbswPXhcLqm5AN5gwcTTyiUGSP2YndWwk9"}, - Hex: "76a9140d1156f6026bf975ea3553b03fb534d0959c294c88ac", - }, - ValueSat: *big.NewInt(167280949), - }, - }, - }, - }} + msg: `{"hex":"03000500010000000000000000000000000000000000000000000000000000000000000000ffffffff170340b00f1291af3c09542bc8349901000000002f4e614effffffff024181f809000000001976a9146a341485a9444b35dc9cb90d24e7483de7d37e0088ac3581f809000000001976a9140d1156f6026bf975ea3553b03fb534d0959c294c88ac0000000026010040b00f000000000000000000000000000000000000000000000000000000000000000000","txid":"71d6975e3b79b52baf26c3269896a34f3bedfb04561c692ffa31f64dada1f9c4","size":181,"version":3,"type":5,"locktime":0,"vin":[{"coinbase":"0340b00f1291af3c09542bc8349901000000002f4e614e","sequence":4294967295}],"vout":[{"value":1.67280961,"valueSat":167280961,"n":0,"scriptPubKey":{"asm":"OP_DUPOP_HASH1606a341485a9444b35dc9cb90d24e7483de7d37e00OP_EQUALVERIFYOP_CHECKSIG","hex":"76a9146a341485a9444b35dc9cb90d24e7483de7d37e0088ac","reqSigs":1,"type":"pubkeyhash","addresses":["XkNPrBSJtrHZUvUqb3JF4g5rMB3uzaJfEL"]}},{"value":1.67280949,"valueSat":167280949,"n":1,"scriptPubKey":{"asm":"OP_DUPOP_HASH1600d1156f6026bf975ea3553b03fb534d0959c294cOP_EQUALVERIFYOP_CHECKSIG","hex":"76a9140d1156f6026bf975ea3553b03fb534d0959c294c88ac","reqSigs":1,"type":"pubkeyhash","addresses":["XbswPXhcLqm5AN5gwcTTyiUGSP2YndWwk9"]}}],"extraPayloadSize":38,"extraPayload":"010040b00f000000000000000000000000000000000000000000000000000000000000000000","cbTx":{"version":1,"height":1028160,"merkleRootMNList":"0000000000000000000000000000000000000000000000000000000000000000"},"blockhash":"000000000000002099caaf1a877911d99a5980ede9b981280eecb291afedf87b","height":1028160,"confirmations":0,"time":1551246710,"blocktime":1551246710,"instantlock":false}`, + want: &testTx2, + }, + } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := p.ParseTxFromJson([]byte(tt.msg)) @@ -249,6 +254,17 @@ func Test_PackTx(t *testing.T) { want: testTxPacked1, wantErr: false, }, + { + name: "dash-2", + args: args{ + tx: testTx2, + height: 1028160, + blockTime: 1551246710, + parser: NewDashParser(GetChainParams("main"), &btc.Configuration{}), + }, + want: testTxPacked2, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -287,6 +303,16 @@ func Test_UnpackTx(t *testing.T) { want1: 1028160, wantErr: false, }, + { + name: "dash-2", + args: args{ + packedTx: testTxPacked2, + parser: NewDashParser(GetChainParams("main"), &btc.Configuration{}), + }, + want: &testTx2, + want1: 1028160, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {