mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00
[DEV-31] Convert all timestamp to uint64
This commit is contained in:
parent
90b71f1bb7
commit
0878f98d1e
@ -447,7 +447,7 @@ func (b *BlockChain) calcSequenceLock(node *blockNode, tx *btcutil.Tx, utxoView
|
|||||||
// number in accordance to BIP-68.
|
// number in accordance to BIP-68.
|
||||||
// See: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
|
// See: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
|
||||||
// * (Compatibility)
|
// * (Compatibility)
|
||||||
func LockTimeToSequence(isSeconds bool, locktime int64) int64 {
|
func LockTimeToSequence(isSeconds bool, locktime uint64) uint64 {
|
||||||
// If we're expressing the relative lock time in blocks, then the
|
// If we're expressing the relative lock time in blocks, then the
|
||||||
// corresponding sequence number is simply the desired input age.
|
// corresponding sequence number is simply the desired input age.
|
||||||
if !isSeconds {
|
if !isSeconds {
|
||||||
|
@ -497,7 +497,7 @@ func dbRemoveSpendJournalEntry(dbTx database.Tx, blockHash *chainhash.Hash) erro
|
|||||||
//
|
//
|
||||||
// Example 1:
|
// Example 1:
|
||||||
// From tx in main blockchain:
|
// From tx in main blockchain:
|
||||||
// Blk 1, c52c57dcdaa5cbfd39ef73afb78b1fbb1e856f557dd5f8b53c49acbf21eb387a:0
|
// Blk 1, b7c3332bc138e2c9429818f5fed500bcc1746544218772389054dc8047d7cd3f:0
|
||||||
//
|
//
|
||||||
// 03320496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52
|
// 03320496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52
|
||||||
// <><------------------------------------------------------------------>
|
// <><------------------------------------------------------------------>
|
||||||
|
@ -7,6 +7,7 @@ package blockchain
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@ -236,7 +237,7 @@ func TestSpendJournalSerialization(t *testing.T) {
|
|||||||
Index: 0,
|
Index: 0,
|
||||||
},
|
},
|
||||||
SignatureScript: hexToBytes("47304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901"),
|
SignatureScript: hexToBytes("47304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901"),
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
}},
|
}},
|
||||||
TxOut: []*wire.TxOut{{
|
TxOut: []*wire.TxOut{{
|
||||||
Value: 1000000000,
|
Value: 1000000000,
|
||||||
@ -271,7 +272,7 @@ func TestSpendJournalSerialization(t *testing.T) {
|
|||||||
Index: 1,
|
Index: 1,
|
||||||
},
|
},
|
||||||
SignatureScript: hexToBytes("493046022100c167eead9840da4a033c9a56470d7794a9bb1605b377ebe5688499b39f94be59022100fb6345cab4324f9ea0b9ee9169337534834638d818129778370f7d378ee4a325014104d962cac5390f12ddb7539507065d0def320d68c040f2e73337c3a1aaaab7195cb5c4d02e0959624d534f3c10c3cf3d73ca5065ebd62ae986b04c6d090d32627c"),
|
SignatureScript: hexToBytes("493046022100c167eead9840da4a033c9a56470d7794a9bb1605b377ebe5688499b39f94be59022100fb6345cab4324f9ea0b9ee9169337534834638d818129778370f7d378ee4a325014104d962cac5390f12ddb7539507065d0def320d68c040f2e73337c3a1aaaab7195cb5c4d02e0959624d534f3c10c3cf3d73ca5065ebd62ae986b04c6d090d32627c"),
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
}},
|
}},
|
||||||
TxOut: []*wire.TxOut{{
|
TxOut: []*wire.TxOut{{
|
||||||
Value: 5000000,
|
Value: 5000000,
|
||||||
@ -289,7 +290,7 @@ func TestSpendJournalSerialization(t *testing.T) {
|
|||||||
Index: 0,
|
Index: 0,
|
||||||
},
|
},
|
||||||
SignatureScript: hexToBytes("483045022100e256743154c097465cf13e89955e1c9ff2e55c46051b627751dee0144183157e02201d8d4f02cde8496aae66768f94d35ce54465bd4ae8836004992d3216a93a13f00141049d23ce8686fe9b802a7a938e8952174d35dd2c2089d4112001ed8089023ab4f93a3c9fcd5bfeaa9727858bf640dc1b1c05ec3b434bb59837f8640e8810e87742"),
|
SignatureScript: hexToBytes("483045022100e256743154c097465cf13e89955e1c9ff2e55c46051b627751dee0144183157e02201d8d4f02cde8496aae66768f94d35ce54465bd4ae8836004992d3216a93a13f00141049d23ce8686fe9b802a7a938e8952174d35dd2c2089d4112001ed8089023ab4f93a3c9fcd5bfeaa9727858bf640dc1b1c05ec3b434bb59837f8640e8810e87742"),
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
}},
|
}},
|
||||||
TxOut: []*wire.TxOut{{
|
TxOut: []*wire.TxOut{{
|
||||||
Value: 5000000,
|
Value: 5000000,
|
||||||
@ -356,7 +357,7 @@ func TestSpendJournalErrors(t *testing.T) {
|
|||||||
Index: 0,
|
Index: 0,
|
||||||
},
|
},
|
||||||
SignatureScript: hexToBytes("47304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901"),
|
SignatureScript: hexToBytes("47304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901"),
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
}},
|
}},
|
||||||
LockTime: 0,
|
LockTime: 0,
|
||||||
}},
|
}},
|
||||||
@ -373,7 +374,7 @@ func TestSpendJournalErrors(t *testing.T) {
|
|||||||
Index: 0,
|
Index: 0,
|
||||||
},
|
},
|
||||||
SignatureScript: hexToBytes("47304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901"),
|
SignatureScript: hexToBytes("47304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901"),
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
}},
|
}},
|
||||||
LockTime: 0,
|
LockTime: 0,
|
||||||
}},
|
}},
|
||||||
@ -413,7 +414,7 @@ func TestUtxoSerialization(t *testing.T) {
|
|||||||
serialized []byte
|
serialized []byte
|
||||||
}{
|
}{
|
||||||
// From tx in main blockchain:
|
// From tx in main blockchain:
|
||||||
// c52c57dcdaa5cbfd39ef73afb78b1fbb1e856f557dd5f8b53c49acbf21eb387a:0
|
// b7c3332bc138e2c9429818f5fed500bcc1746544218772389054dc8047d7cd3f:0
|
||||||
{
|
{
|
||||||
name: "height 1, coinbase",
|
name: "height 1, coinbase",
|
||||||
entry: &UtxoEntry{
|
entry: &UtxoEntry{
|
||||||
@ -425,7 +426,7 @@ func TestUtxoSerialization(t *testing.T) {
|
|||||||
serialized: hexToBytes("03320496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52"),
|
serialized: hexToBytes("03320496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52"),
|
||||||
},
|
},
|
||||||
// From tx in main blockchain:
|
// From tx in main blockchain:
|
||||||
// c52c57dcdaa5cbfd39ef73afb78b1fbb1e856f557dd5f8b53c49acbf21eb387a:0
|
// b7c3332bc138e2c9429818f5fed500bcc1746544218772389054dc8047d7cd3f:0
|
||||||
{
|
{
|
||||||
name: "height 1, coinbase, spent",
|
name: "height 1, coinbase, spent",
|
||||||
entry: &UtxoEntry{
|
entry: &UtxoEntry{
|
||||||
|
@ -6,6 +6,7 @@ package fullblocktests
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ var (
|
|||||||
"32303039204368616e63656c6c6f72206f" +
|
"32303039204368616e63656c6c6f72206f" +
|
||||||
"6e206272696e6b206f66207365636f6e64" +
|
"6e206272696e6b206f66207365636f6e64" +
|
||||||
"206261696c6f757420666f72206261686b73"),
|
"206261696c6f757420666f72206261686b73"),
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
}},
|
}},
|
||||||
TxOut: []*wire.TxOut{{
|
TxOut: []*wire.TxOut{{
|
||||||
Value: 0,
|
Value: 0,
|
||||||
|
@ -267,7 +267,7 @@ func determineMainChainBlocks(blocksMap map[chainhash.Hash]*blockChainContext, t
|
|||||||
//
|
//
|
||||||
// Example 1:
|
// Example 1:
|
||||||
// From tx in main blockchain:
|
// From tx in main blockchain:
|
||||||
// Blk 1, c52c57dcdaa5cbfd39ef73afb78b1fbb1e856f557dd5f8b53c49acbf21eb387a
|
// Blk 1, b7c3332bc138e2c9429818f5fed500bcc1746544218772389054dc8047d7cd3f
|
||||||
//
|
//
|
||||||
// 010103320496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52
|
// 010103320496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52
|
||||||
// <><><><------------------------------------------------------------------>
|
// <><><><------------------------------------------------------------------>
|
||||||
|
@ -18,7 +18,7 @@ func TestDeserializeUtxoEntryV0(t *testing.T) {
|
|||||||
serialized []byte
|
serialized []byte
|
||||||
}{
|
}{
|
||||||
// From tx in main blockchain:
|
// From tx in main blockchain:
|
||||||
// c52c57dcdaa5cbfd39ef73afb78b1fbb1e856f557dd5f8b53c49acbf21eb387a
|
// b7c3332bc138e2c9429818f5fed500bcc1746544218772389054dc8047d7cd3f
|
||||||
{
|
{
|
||||||
name: "Only output 0, coinbase",
|
name: "Only output 0, coinbase",
|
||||||
entries: map[uint32]*UtxoEntry{
|
entries: map[uint32]*UtxoEntry{
|
||||||
|
@ -167,7 +167,7 @@ func IsFinalizedTransaction(tx *btcutil.Tx, blockHeight int32, blockTime time.Ti
|
|||||||
// the transaction might still be finalized if the sequence number
|
// the transaction might still be finalized if the sequence number
|
||||||
// for all transaction inputs is maxed out.
|
// for all transaction inputs is maxed out.
|
||||||
for _, txIn := range msgTx.TxIn {
|
for _, txIn := range msgTx.TxIn {
|
||||||
if txIn.Sequence != math.MaxUint32 {
|
if txIn.Sequence != math.MaxUint64 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ var Block100000 = wire.MsgBlock{
|
|||||||
SignatureScript: []byte{
|
SignatureScript: []byte{
|
||||||
0x04, 0x4c, 0x86, 0x04, 0x1b, 0x02, 0x06, 0x02,
|
0x04, 0x4c, 0x86, 0x04, 0x1b, 0x02, 0x06, 0x02,
|
||||||
},
|
},
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TxOut: []*wire.TxOut{
|
TxOut: []*wire.TxOut{
|
||||||
@ -326,7 +326,7 @@ var Block100000 = wire.MsgBlock{
|
|||||||
0xc6, 0xf8, 0xa6, 0x30, 0x12, 0x1d, 0xf2, 0xb3,
|
0xc6, 0xf8, 0xa6, 0x30, 0x12, 0x1d, 0xf2, 0xb3,
|
||||||
0xd3, // 65-byte pubkey
|
0xd3, // 65-byte pubkey
|
||||||
},
|
},
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TxOut: []*wire.TxOut{
|
TxOut: []*wire.TxOut{
|
||||||
@ -394,7 +394,7 @@ var Block100000 = wire.MsgBlock{
|
|||||||
0x60, 0x63, 0x9d, 0xb4, 0x62, 0xe9, 0xcb, 0x85,
|
0x60, 0x63, 0x9d, 0xb4, 0x62, 0xe9, 0xcb, 0x85,
|
||||||
0x0f, // 65-byte pubkey
|
0x0f, // 65-byte pubkey
|
||||||
},
|
},
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TxOut: []*wire.TxOut{
|
TxOut: []*wire.TxOut{
|
||||||
@ -463,7 +463,7 @@ var Block100000 = wire.MsgBlock{
|
|||||||
0x6a, 0xf4, 0xcf, 0xaa, 0xea, 0x4e, 0xa1, 0x4f,
|
0x6a, 0xf4, 0xcf, 0xaa, 0xea, 0x4e, 0xa1, 0x4f,
|
||||||
0xbb, // 65-byte pubkey
|
0xbb, // 65-byte pubkey
|
||||||
},
|
},
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TxOut: []*wire.TxOut{
|
TxOut: []*wire.TxOut{
|
||||||
|
@ -57,7 +57,7 @@ type TransactionInput struct {
|
|||||||
type CreateRawTransactionCmd struct {
|
type CreateRawTransactionCmd struct {
|
||||||
Inputs []TransactionInput
|
Inputs []TransactionInput
|
||||||
Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC
|
Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC
|
||||||
LockTime *int64
|
LockTime *uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCreateRawTransactionCmd returns a new instance which can be used to issue
|
// NewCreateRawTransactionCmd returns a new instance which can be used to issue
|
||||||
@ -65,7 +65,7 @@ type CreateRawTransactionCmd struct {
|
|||||||
//
|
//
|
||||||
// Amounts are in BTC.
|
// Amounts are in BTC.
|
||||||
func NewCreateRawTransactionCmd(inputs []TransactionInput, amounts map[string]float64,
|
func NewCreateRawTransactionCmd(inputs []TransactionInput, amounts map[string]float64,
|
||||||
lockTime *int64) *CreateRawTransactionCmd {
|
lockTime *uint64) *CreateRawTransactionCmd {
|
||||||
|
|
||||||
return &CreateRawTransactionCmd{
|
return &CreateRawTransactionCmd{
|
||||||
Inputs: inputs,
|
Inputs: inputs,
|
||||||
|
@ -77,7 +77,7 @@ func TestChainSvrCmds(t *testing.T) {
|
|||||||
unmarshalled: &btcjson.CreateRawTransactionCmd{
|
unmarshalled: &btcjson.CreateRawTransactionCmd{
|
||||||
Inputs: []btcjson.TransactionInput{{Txid: "123", Vout: 1}},
|
Inputs: []btcjson.TransactionInput{{Txid: "123", Vout: 1}},
|
||||||
Amounts: map[string]float64{"456": .0123},
|
Amounts: map[string]float64{"456": .0123},
|
||||||
LockTime: btcjson.Int64(12312333333),
|
LockTime: btcjson.Uint64(12312333333),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ type Vin struct {
|
|||||||
Txid string `json:"txid"`
|
Txid string `json:"txid"`
|
||||||
Vout uint32 `json:"vout"`
|
Vout uint32 `json:"vout"`
|
||||||
ScriptSig *ScriptSig `json:"scriptSig"`
|
ScriptSig *ScriptSig `json:"scriptSig"`
|
||||||
Sequence uint32 `json:"sequence"`
|
Sequence uint64 `json:"sequence"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsCoinBase returns a bool to show if a Vin is a Coinbase one or not.
|
// IsCoinBase returns a bool to show if a Vin is a Coinbase one or not.
|
||||||
@ -320,7 +320,7 @@ func (v *Vin) MarshalJSON() ([]byte, error) {
|
|||||||
if v.IsCoinBase() {
|
if v.IsCoinBase() {
|
||||||
coinbaseStruct := struct {
|
coinbaseStruct := struct {
|
||||||
Coinbase string `json:"coinbase"`
|
Coinbase string `json:"coinbase"`
|
||||||
Sequence uint32 `json:"sequence"`
|
Sequence uint64 `json:"sequence"`
|
||||||
}{
|
}{
|
||||||
Coinbase: v.Coinbase,
|
Coinbase: v.Coinbase,
|
||||||
Sequence: v.Sequence,
|
Sequence: v.Sequence,
|
||||||
@ -332,7 +332,7 @@ func (v *Vin) MarshalJSON() ([]byte, error) {
|
|||||||
Txid string `json:"txid"`
|
Txid string `json:"txid"`
|
||||||
Vout uint32 `json:"vout"`
|
Vout uint32 `json:"vout"`
|
||||||
ScriptSig *ScriptSig `json:"scriptSig"`
|
ScriptSig *ScriptSig `json:"scriptSig"`
|
||||||
Sequence uint32 `json:"sequence"`
|
Sequence uint64 `json:"sequence"`
|
||||||
}{
|
}{
|
||||||
Txid: v.Txid,
|
Txid: v.Txid,
|
||||||
Vout: v.Vout,
|
Vout: v.Vout,
|
||||||
@ -355,7 +355,7 @@ type VinPrevOut struct {
|
|||||||
Vout uint32 `json:"vout"`
|
Vout uint32 `json:"vout"`
|
||||||
ScriptSig *ScriptSig `json:"scriptSig"`
|
ScriptSig *ScriptSig `json:"scriptSig"`
|
||||||
PrevOut *PrevOut `json:"prevOut"`
|
PrevOut *PrevOut `json:"prevOut"`
|
||||||
Sequence uint32 `json:"sequence"`
|
Sequence uint64 `json:"sequence"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsCoinBase returns a bool to show if a Vin is a Coinbase one or not.
|
// IsCoinBase returns a bool to show if a Vin is a Coinbase one or not.
|
||||||
@ -368,7 +368,7 @@ func (v *VinPrevOut) MarshalJSON() ([]byte, error) {
|
|||||||
if v.IsCoinBase() {
|
if v.IsCoinBase() {
|
||||||
coinbaseStruct := struct {
|
coinbaseStruct := struct {
|
||||||
Coinbase string `json:"coinbase"`
|
Coinbase string `json:"coinbase"`
|
||||||
Sequence uint32 `json:"sequence"`
|
Sequence uint64 `json:"sequence"`
|
||||||
}{
|
}{
|
||||||
Coinbase: v.Coinbase,
|
Coinbase: v.Coinbase,
|
||||||
Sequence: v.Sequence,
|
Sequence: v.Sequence,
|
||||||
@ -381,7 +381,7 @@ func (v *VinPrevOut) MarshalJSON() ([]byte, error) {
|
|||||||
Vout uint32 `json:"vout"`
|
Vout uint32 `json:"vout"`
|
||||||
ScriptSig *ScriptSig `json:"scriptSig"`
|
ScriptSig *ScriptSig `json:"scriptSig"`
|
||||||
PrevOut *PrevOut `json:"prevOut,omitempty"`
|
PrevOut *PrevOut `json:"prevOut,omitempty"`
|
||||||
Sequence uint32 `json:"sequence"`
|
Sequence uint64 `json:"sequence"`
|
||||||
}{
|
}{
|
||||||
Txid: v.Txid,
|
Txid: v.Txid,
|
||||||
Vout: v.Vout,
|
Vout: v.Vout,
|
||||||
@ -444,13 +444,13 @@ type TxRawResult struct {
|
|||||||
Hash string `json:"hash,omitempty"`
|
Hash string `json:"hash,omitempty"`
|
||||||
Size int32 `json:"size,omitempty"`
|
Size int32 `json:"size,omitempty"`
|
||||||
Version int32 `json:"version"`
|
Version int32 `json:"version"`
|
||||||
LockTime int64 `json:"locktime"`
|
LockTime uint64 `json:"locktime"`
|
||||||
Vin []Vin `json:"vin"`
|
Vin []Vin `json:"vin"`
|
||||||
Vout []Vout `json:"vout"`
|
Vout []Vout `json:"vout"`
|
||||||
BlockHash string `json:"blockhash,omitempty"`
|
BlockHash string `json:"blockhash,omitempty"`
|
||||||
Confirmations uint64 `json:"confirmations,omitempty"`
|
Confirmations uint64 `json:"confirmations,omitempty"`
|
||||||
Time int64 `json:"time,omitempty"`
|
Time int64 `json:"time,omitempty"`
|
||||||
Blocktime int64 `json:"blocktime,omitempty"`
|
Blocktime uint64 `json:"blocktime,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchRawTransactionsResult models the data from the searchrawtransaction
|
// SearchRawTransactionsResult models the data from the searchrawtransaction
|
||||||
@ -461,20 +461,20 @@ type SearchRawTransactionsResult struct {
|
|||||||
Hash string `json:"hash"`
|
Hash string `json:"hash"`
|
||||||
Size string `json:"size"`
|
Size string `json:"size"`
|
||||||
Version int32 `json:"version"`
|
Version int32 `json:"version"`
|
||||||
LockTime int64 `json:"locktime"`
|
LockTime uint64 `json:"locktime"`
|
||||||
Vin []VinPrevOut `json:"vin"`
|
Vin []VinPrevOut `json:"vin"`
|
||||||
Vout []Vout `json:"vout"`
|
Vout []Vout `json:"vout"`
|
||||||
BlockHash string `json:"blockhash,omitempty"`
|
BlockHash string `json:"blockhash,omitempty"`
|
||||||
Confirmations uint64 `json:"confirmations,omitempty"`
|
Confirmations uint64 `json:"confirmations,omitempty"`
|
||||||
Time int64 `json:"time,omitempty"`
|
Time uint64 `json:"time,omitempty"`
|
||||||
Blocktime int64 `json:"blocktime,omitempty"`
|
Blocktime uint64 `json:"blocktime,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TxRawDecodeResult models the data from the decoderawtransaction command.
|
// TxRawDecodeResult models the data from the decoderawtransaction command.
|
||||||
type TxRawDecodeResult struct {
|
type TxRawDecodeResult struct {
|
||||||
Txid string `json:"txid"`
|
Txid string `json:"txid"`
|
||||||
Version int32 `json:"version"`
|
Version int32 `json:"version"`
|
||||||
Locktime int64 `json:"locktime"`
|
Locktime uint64 `json:"locktime"`
|
||||||
Vin []Vin `json:"vin"`
|
Vin []Vin `json:"vin"`
|
||||||
Vout []Vout `json:"vout"`
|
Vout []Vout `json:"vout"`
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ type GetTransactionResult struct {
|
|||||||
Confirmations int64 `json:"confirmations"`
|
Confirmations int64 `json:"confirmations"`
|
||||||
BlockHash string `json:"blockhash"`
|
BlockHash string `json:"blockhash"`
|
||||||
BlockIndex int64 `json:"blockindex"`
|
BlockIndex int64 `json:"blockindex"`
|
||||||
BlockTime int64 `json:"blocktime"`
|
BlockTime uint64 `json:"blocktime"`
|
||||||
TxID string `json:"txid"`
|
TxID string `json:"txid"`
|
||||||
WalletConflicts []string `json:"walletconflicts"`
|
WalletConflicts []string `json:"walletconflicts"`
|
||||||
Time int64 `json:"time"`
|
Time int64 `json:"time"`
|
||||||
@ -65,7 +65,7 @@ type ListTransactionsResult struct {
|
|||||||
BIP125Replaceable string `json:"bip125-replaceable,omitempty"`
|
BIP125Replaceable string `json:"bip125-replaceable,omitempty"`
|
||||||
BlockHash string `json:"blockhash,omitempty"`
|
BlockHash string `json:"blockhash,omitempty"`
|
||||||
BlockIndex *int64 `json:"blockindex,omitempty"`
|
BlockIndex *int64 `json:"blockindex,omitempty"`
|
||||||
BlockTime int64 `json:"blocktime,omitempty"`
|
BlockTime uint64 `json:"blocktime,omitempty"`
|
||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Confirmations int64 `json:"confirmations"`
|
Confirmations int64 `json:"confirmations"`
|
||||||
Fee *float64 `json:"fee,omitempty"`
|
Fee *float64 `json:"fee,omitempty"`
|
||||||
@ -125,7 +125,7 @@ type SignRawTransactionError struct {
|
|||||||
TxID string `json:"txid"`
|
TxID string `json:"txid"`
|
||||||
Vout uint32 `json:"vout"`
|
Vout uint32 `json:"vout"`
|
||||||
ScriptSig string `json:"scriptSig"`
|
ScriptSig string `json:"scriptSig"`
|
||||||
Sequence uint32 `json:"sequence"`
|
Sequence uint64 `json:"sequence"`
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package chaincfg
|
package chaincfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/daglabs/btcd/chaincfg/chainhash"
|
"github.com/daglabs/btcd/chaincfg/chainhash"
|
||||||
@ -33,7 +34,7 @@ var genesisCoinbaseTx = wire.MsgTx{
|
|||||||
0x6f, 0x75, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, /* |out for |*/
|
0x6f, 0x75, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, /* |out for |*/
|
||||||
0x62, 0x61, 0x6e, 0x6b, 0x73, /* |banks| */
|
0x62, 0x61, 0x6e, 0x6b, 0x73, /* |banks| */
|
||||||
},
|
},
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TxOut: []*wire.TxOut{
|
TxOut: []*wire.TxOut{
|
||||||
|
@ -245,7 +245,7 @@ func createCSVOutput(r *rpctest.Harness, t *testing.T,
|
|||||||
sequenceLock := blockchain.LockTimeToSequence(isSeconds,
|
sequenceLock := blockchain.LockTimeToSequence(isSeconds,
|
||||||
int64(timeLock))
|
int64(timeLock))
|
||||||
|
|
||||||
// Our CSV script is simply: <sequenceLock> OP_CSV OP_DROP
|
// Our CSV script is simply: <sequenceLock> OP_CSV
|
||||||
b := txscript.NewScriptBuilder().
|
b := txscript.NewScriptBuilder().
|
||||||
AddInt64(int64(sequenceLock)).
|
AddInt64(int64(sequenceLock)).
|
||||||
AddOp(txscript.OpCheckSequenceVerify)
|
AddOp(txscript.OpCheckSequenceVerify)
|
||||||
@ -293,7 +293,7 @@ func createCSVOutput(r *rpctest.Harness, t *testing.T,
|
|||||||
// function. The sigScript is a trivial push of OP_TRUE followed by the
|
// function. The sigScript is a trivial push of OP_TRUE followed by the
|
||||||
// redeemScript to pass P2SH evaluation.
|
// redeemScript to pass P2SH evaluation.
|
||||||
func spendCSVOutput(redeemScript []byte, csvUTXO *wire.OutPoint,
|
func spendCSVOutput(redeemScript []byte, csvUTXO *wire.OutPoint,
|
||||||
sequence uint32, targetOutput *wire.TxOut,
|
sequence uint64, targetOutput *wire.TxOut,
|
||||||
txVersion int32) (*wire.MsgTx, error) {
|
txVersion int32) (*wire.MsgTx, error) {
|
||||||
|
|
||||||
tx := wire.NewMsgTx(txVersion)
|
tx := wire.NewMsgTx(txVersion)
|
||||||
@ -456,7 +456,7 @@ func TestBIP0068AndCsv(t *testing.T) {
|
|||||||
// A helper function to create fully signed transactions in-line during
|
// A helper function to create fully signed transactions in-line during
|
||||||
// the array initialization below.
|
// the array initialization below.
|
||||||
var inputIndex uint32
|
var inputIndex uint32
|
||||||
makeTxCase := func(sequenceNum uint32, txVersion int32) *wire.MsgTx {
|
makeTxCase := func(sequenceNum uint64, txVersion int32) *wire.MsgTx {
|
||||||
csvInput := spendableInputs[inputIndex]
|
csvInput := spendableInputs[inputIndex]
|
||||||
|
|
||||||
tx, err := spendCSVOutput(csvInput.RedeemScript, csvInput.Utxo,
|
tx, err := spendCSVOutput(csvInput.RedeemScript, csvInput.Utxo,
|
||||||
|
@ -6,6 +6,7 @@ package mining
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/daglabs/btcd/blockchain"
|
"github.com/daglabs/btcd/blockchain"
|
||||||
@ -69,7 +70,7 @@ func TestCalcPriority(t *testing.T) {
|
|||||||
Index: wire.MaxPrevOutIndex,
|
Index: wire.MaxPrevOutIndex,
|
||||||
},
|
},
|
||||||
SignatureScript: hexToBytes("04ffff001d0134"),
|
SignatureScript: hexToBytes("04ffff001d0134"),
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
}},
|
}},
|
||||||
TxOut: []*wire.TxOut{{
|
TxOut: []*wire.TxOut{{
|
||||||
Value: 5000000000,
|
Value: 5000000000,
|
||||||
@ -98,7 +99,7 @@ func TestCalcPriority(t *testing.T) {
|
|||||||
"514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5f" +
|
"514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5f" +
|
||||||
"b8cd410220181522ec8eca07de4860a4acdd12909d83" +
|
"b8cd410220181522ec8eca07de4860a4acdd12909d83" +
|
||||||
"1cc56cbbac4622082221a8768d1d0901"),
|
"1cc56cbbac4622082221a8768d1d0901"),
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
}},
|
}},
|
||||||
TxOut: []*wire.TxOut{{
|
TxOut: []*wire.TxOut{{
|
||||||
Value: 1000000000,
|
Value: 1000000000,
|
||||||
|
@ -65,7 +65,7 @@ func directionString(inbound bool) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// formatLockTime returns a transaction lock time as a human-readable string.
|
// formatLockTime returns a transaction lock time as a human-readable string.
|
||||||
func formatLockTime(lockTime int64) string {
|
func formatLockTime(lockTime uint64) string {
|
||||||
// The lock time field of a transaction is either a block height at
|
// The lock time field of a transaction is either a block height at
|
||||||
// which the transaction is finalized or a timestamp depending on if the
|
// which the transaction is finalized or a timestamp depending on if the
|
||||||
// value is before the lockTimeThreshold. When it is under the
|
// value is before the lockTimeThreshold. When it is under the
|
||||||
|
@ -239,7 +239,7 @@ func (r FutureCreateRawTransactionResult) Receive() (*wire.MsgTx, error) {
|
|||||||
//
|
//
|
||||||
// See CreateRawTransaction for the blocking version and more details.
|
// See CreateRawTransaction for the blocking version and more details.
|
||||||
func (c *Client) CreateRawTransactionAsync(inputs []btcjson.TransactionInput,
|
func (c *Client) CreateRawTransactionAsync(inputs []btcjson.TransactionInput,
|
||||||
amounts map[btcutil.Address]btcutil.Amount, lockTime *int64) FutureCreateRawTransactionResult {
|
amounts map[btcutil.Address]btcutil.Amount, lockTime *uint64) FutureCreateRawTransactionResult {
|
||||||
|
|
||||||
convertedAmts := make(map[string]float64, len(amounts))
|
convertedAmts := make(map[string]float64, len(amounts))
|
||||||
for addr, amount := range amounts {
|
for addr, amount := range amounts {
|
||||||
@ -252,7 +252,7 @@ func (c *Client) CreateRawTransactionAsync(inputs []btcjson.TransactionInput,
|
|||||||
// CreateRawTransaction returns a new transaction spending the provided inputs
|
// CreateRawTransaction returns a new transaction spending the provided inputs
|
||||||
// and sending to the provided addresses.
|
// and sending to the provided addresses.
|
||||||
func (c *Client) CreateRawTransaction(inputs []btcjson.TransactionInput,
|
func (c *Client) CreateRawTransaction(inputs []btcjson.TransactionInput,
|
||||||
amounts map[btcutil.Address]btcutil.Amount, lockTime *int64) (*wire.MsgTx, error) {
|
amounts map[btcutil.Address]btcutil.Amount, lockTime *uint64) (*wire.MsgTx, error) {
|
||||||
|
|
||||||
return c.CreateRawTransactionAsync(inputs, amounts, lockTime).Receive()
|
return c.CreateRawTransactionAsync(inputs, amounts, lockTime).Receive()
|
||||||
}
|
}
|
||||||
|
@ -514,7 +514,7 @@ func handleCreateRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan
|
|||||||
|
|
||||||
// Validate the locktime, if given.
|
// Validate the locktime, if given.
|
||||||
if c.LockTime != nil &&
|
if c.LockTime != nil &&
|
||||||
(*c.LockTime < 0 || *c.LockTime > int64(wire.MaxTxInSequenceNum)) {
|
(*c.LockTime < 0 || *c.LockTime > wire.MaxTxInSequenceNum) {
|
||||||
return nil, &btcjson.RPCError{
|
return nil, &btcjson.RPCError{
|
||||||
Code: btcjson.ErrRPCInvalidParameter,
|
Code: btcjson.ErrRPCInvalidParameter,
|
||||||
Message: "Locktime out of range",
|
Message: "Locktime out of range",
|
||||||
@ -599,7 +599,7 @@ func handleCreateRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan
|
|||||||
|
|
||||||
// Set the Locktime, if given.
|
// Set the Locktime, if given.
|
||||||
if c.LockTime != nil {
|
if c.LockTime != nil {
|
||||||
mtx.LockTime = int64(*c.LockTime)
|
mtx.LockTime = *c.LockTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the serialized and hex-encoded transaction. Note that this
|
// Return the serialized and hex-encoded transaction. Note that this
|
||||||
|
@ -1066,7 +1066,7 @@ func opcodeReturn(op *parsedOpcode, vm *Engine) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// verifyLockTime is a helper function used to validate locktimes.
|
// verifyLockTime is a helper function used to validate locktimes.
|
||||||
func verifyLockTime(txLockTime, threshold, lockTime int64) error {
|
func verifyLockTime(txLockTime, threshold, lockTime uint64) error {
|
||||||
// The lockTimes in both the script and transaction must be of the same
|
// The lockTimes in both the script and transaction must be of the same
|
||||||
// type.
|
// type.
|
||||||
if !((txLockTime < threshold && lockTime < threshold) ||
|
if !((txLockTime < threshold && lockTime < threshold) ||
|
||||||
@ -1118,8 +1118,8 @@ func opcodeCheckLockTimeVerify(op *parsedOpcode, vm *Engine) error {
|
|||||||
// which the transaction is finalized or a timestamp depending on if the
|
// which the transaction is finalized or a timestamp depending on if the
|
||||||
// value is before the txscript.LockTimeThreshold. When it is under the
|
// value is before the txscript.LockTimeThreshold. When it is under the
|
||||||
// threshold it is a block height.
|
// threshold it is a block height.
|
||||||
err = verifyLockTime(int64(vm.tx.LockTime), LockTimeThreshold,
|
err = verifyLockTime(vm.tx.LockTime, LockTimeThreshold,
|
||||||
int64(lockTime))
|
uint64(lockTime))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1151,12 +1151,12 @@ func opcodeCheckLockTimeVerify(op *parsedOpcode, vm *Engine) error {
|
|||||||
// validating if the transaction outputs are spendable yet.
|
// validating if the transaction outputs are spendable yet.
|
||||||
func opcodeCheckSequenceVerify(op *parsedOpcode, vm *Engine) error {
|
func opcodeCheckSequenceVerify(op *parsedOpcode, vm *Engine) error {
|
||||||
|
|
||||||
// The current transaction sequence is a uint32 resulting in a maximum
|
// The current transaction sequence is a uint64 resulting in a maximum
|
||||||
// sequence of 2^32-1. However, scriptNums are signed and therefore a
|
// sequence of 2^32-1. However, scriptNums are signed and therefore a
|
||||||
// standard 4-byte scriptNum would only support up to a maximum of
|
// standard 4-byte scriptNum would only support up to a maximum of
|
||||||
// 2^31-1. Thus, a 5-byte scriptNum is used here since it will support
|
// 2^31-1. Thus, a 5-byte scriptNum is used here since it will support
|
||||||
// up to 2^39-1 which allows sequences beyond the current sequence
|
// up to 2^39-1 which allows sequences beyond the current sequence
|
||||||
// limit.
|
// limit. TODO: Understand this
|
||||||
//
|
//
|
||||||
// PopByteArray is used here instead of PopInt because we do not want
|
// PopByteArray is used here instead of PopInt because we do not want
|
||||||
// to be limited to a 4-byte integer for reasons specified above.
|
// to be limited to a 4-byte integer for reasons specified above.
|
||||||
@ -1177,12 +1177,12 @@ func opcodeCheckSequenceVerify(op *parsedOpcode, vm *Engine) error {
|
|||||||
return scriptError(ErrNegativeLockTime, str)
|
return scriptError(ErrNegativeLockTime, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
sequence := int64(stackSequence)
|
sequence := uint64(stackSequence)
|
||||||
|
|
||||||
// To provide for future soft-fork extensibility, if the
|
// To provide for future soft-fork extensibility, if the
|
||||||
// operand has the disabled lock-time flag set,
|
// operand has the disabled lock-time flag set,
|
||||||
// CHECKSEQUENCEVERIFY behaves as a NOP.
|
// CHECKSEQUENCEVERIFY behaves as a NOP.
|
||||||
if sequence&int64(wire.SequenceLockTimeDisabled) != 0 {
|
if sequence&uint64(wire.SequenceLockTimeDisabled) != 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1190,15 +1190,15 @@ func opcodeCheckSequenceVerify(op *parsedOpcode, vm *Engine) error {
|
|||||||
// consensus constrained. Testing that the transaction's sequence
|
// consensus constrained. Testing that the transaction's sequence
|
||||||
// number does not have this bit set prevents using this property
|
// number does not have this bit set prevents using this property
|
||||||
// to get around a CHECKSEQUENCEVERIFY check.
|
// to get around a CHECKSEQUENCEVERIFY check.
|
||||||
txSequence := int64(vm.tx.TxIn[vm.txIdx].Sequence)
|
txSequence := vm.tx.TxIn[vm.txIdx].Sequence
|
||||||
if txSequence&int64(wire.SequenceLockTimeDisabled) != 0 {
|
if txSequence&wire.SequenceLockTimeDisabled != 0 {
|
||||||
str := fmt.Sprintf("transaction sequence has sequence "+
|
str := fmt.Sprintf("transaction sequence has sequence "+
|
||||||
"locktime disabled bit set: 0x%x", txSequence)
|
"locktime disabled bit set: 0x%x", txSequence)
|
||||||
return scriptError(ErrUnsatisfiedLockTime, str)
|
return scriptError(ErrUnsatisfiedLockTime, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mask off non-consensus bits before doing comparisons.
|
// Mask off non-consensus bits before doing comparisons.
|
||||||
lockTimeMask := int64(wire.SequenceLockTimeIsSeconds |
|
lockTimeMask := uint64(wire.SequenceLockTimeIsSeconds |
|
||||||
wire.SequenceLockTimeMask)
|
wire.SequenceLockTimeMask)
|
||||||
return verifyLockTime(txSequence&lockTimeMask,
|
return verifyLockTime(txSequence&lockTimeMask,
|
||||||
wire.SequenceLockTimeIsSeconds, sequence&lockTimeMask)
|
wire.SequenceLockTimeIsSeconds, sequence&lockTimeMask)
|
||||||
|
@ -501,7 +501,7 @@ type AtomicSwapDataPushes struct {
|
|||||||
RefundHash160 [20]byte
|
RefundHash160 [20]byte
|
||||||
SecretHash [32]byte
|
SecretHash [32]byte
|
||||||
SecretSize int64
|
SecretSize int64
|
||||||
LockTime int64
|
LockTime uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractAtomicSwapDataPushes returns the data pushes from an atomic swap
|
// ExtractAtomicSwapDataPushes returns the data pushes from an atomic swap
|
||||||
@ -568,9 +568,9 @@ func ExtractAtomicSwapDataPushes(version uint16, pkScript []byte) (*AtomicSwapDa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
pushes.LockTime = int64(locktime)
|
pushes.LockTime = uint64(locktime)
|
||||||
} else if op := pops[11].opcode; isSmallInt(op) {
|
} else if op := pops[11].opcode; isSmallInt(op) {
|
||||||
pushes.LockTime = int64(asSmallInt(op))
|
pushes.LockTime = uint64(asSmallInt(op))
|
||||||
} else {
|
} else {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"compress/bzip2"
|
"compress/bzip2"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@ -38,7 +39,7 @@ var genesisCoinbaseTx = MsgTx{
|
|||||||
0x6f, 0x75, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, /* |out for |*/
|
0x6f, 0x75, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, /* |out for |*/
|
||||||
0x62, 0x61, 0x6e, 0x6b, 0x73, /* |banks| */
|
0x62, 0x61, 0x6e, 0x6b, 0x73, /* |banks| */
|
||||||
},
|
},
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TxOut: []*TxOut{
|
TxOut: []*TxOut{
|
||||||
@ -251,7 +252,7 @@ func BenchmarkReadTxIn(b *testing.B) {
|
|||||||
0xff, 0xff, 0xff, 0xff, // Previous output index
|
0xff, 0xff, 0xff, 0xff, // Previous output index
|
||||||
0x07, // Varint for length of signature script
|
0x07, // Varint for length of signature script
|
||||||
0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, // Signature script
|
0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, // Signature script
|
||||||
0xff, 0xff, 0xff, 0xff, // Sequence
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Sequence
|
||||||
}
|
}
|
||||||
r := bytes.NewReader(buf)
|
r := bytes.NewReader(buf)
|
||||||
var txIn TxIn
|
var txIn TxIn
|
||||||
@ -284,7 +285,7 @@ func BenchmarkDeserializeTxSmall(b *testing.B) {
|
|||||||
0xff, 0xff, 0xff, 0xff, // Prevous output index
|
0xff, 0xff, 0xff, 0xff, // Prevous output index
|
||||||
0x07, // Varint for length of signature script
|
0x07, // Varint for length of signature script
|
||||||
0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, // Signature script
|
0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, // Signature script
|
||||||
0xff, 0xff, 0xff, 0xff, // Sequence
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Sequence
|
||||||
0x01, // Varint for number of output transactions
|
0x01, // Varint for number of output transactions
|
||||||
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
|
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
|
||||||
0x43, // Varint for length of pk script
|
0x43, // Varint for length of pk script
|
||||||
|
@ -89,7 +89,7 @@ func TestMessage(t *testing.T) {
|
|||||||
{msgGetAddr, msgGetAddr, pver, MainNet, 24},
|
{msgGetAddr, msgGetAddr, pver, MainNet, 24},
|
||||||
{msgAddr, msgAddr, pver, MainNet, 25},
|
{msgAddr, msgAddr, pver, MainNet, 25},
|
||||||
{msgGetBlocks, msgGetBlocks, pver, MainNet, 61},
|
{msgGetBlocks, msgGetBlocks, pver, MainNet, 61},
|
||||||
{msgBlock, msgBlock, pver, MainNet, 247},
|
{msgBlock, msgBlock, pver, MainNet, 251},
|
||||||
{msgInv, msgInv, pver, MainNet, 25},
|
{msgInv, msgInv, pver, MainNet, 25},
|
||||||
{msgGetData, msgGetData, pver, MainNet, 25},
|
{msgGetData, msgGetData, pver, MainNet, 25},
|
||||||
{msgNotFound, msgNotFound, pver, MainNet, 25},
|
{msgNotFound, msgNotFound, pver, MainNet, 25},
|
||||||
|
@ -7,6 +7,7 @@ package wire
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -71,7 +72,7 @@ func TestBlock(t *testing.T) {
|
|||||||
// hashes from a block accurately.
|
// hashes from a block accurately.
|
||||||
func TestBlockTxHashes(t *testing.T) {
|
func TestBlockTxHashes(t *testing.T) {
|
||||||
// Block 1, transaction 1 hash.
|
// Block 1, transaction 1 hash.
|
||||||
hashStr := "c52c57dcdaa5cbfd39ef73afb78b1fbb1e856f557dd5f8b53c49acbf21eb387a"
|
hashStr := "b7c3332bc138e2c9429818f5fed500bcc1746544218772389054dc8047d7cd3f"
|
||||||
wantHash, err := chainhash.NewHashFromStr(hashStr)
|
wantHash, err := chainhash.NewHashFromStr(hashStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("NewHashFromStr: %v", err)
|
t.Errorf("NewHashFromStr: %v", err)
|
||||||
@ -506,7 +507,7 @@ var blockOne = MsgBlock{
|
|||||||
SignatureScript: []byte{
|
SignatureScript: []byte{
|
||||||
0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04,
|
0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04,
|
||||||
},
|
},
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TxOut: []*TxOut{
|
TxOut: []*TxOut{
|
||||||
@ -556,7 +557,7 @@ var blockOneBytes = []byte{
|
|||||||
0xff, 0xff, 0xff, 0xff, // Prevous output index
|
0xff, 0xff, 0xff, 0xff, // Prevous output index
|
||||||
0x07, // Varint for length of signature script
|
0x07, // Varint for length of signature script
|
||||||
0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, // Signature script (coinbase)
|
0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, // Signature script (coinbase)
|
||||||
0xff, 0xff, 0xff, 0xff, // Sequence
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Sequence
|
||||||
0x01, // Varint for number of transaction outputs
|
0x01, // Varint for number of transaction outputs
|
||||||
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
|
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
|
||||||
0x43, // Varint for length of pk script
|
0x43, // Varint for length of pk script
|
||||||
@ -576,5 +577,5 @@ var blockOneBytes = []byte{
|
|||||||
|
|
||||||
// Transaction location information for block one transactions.
|
// Transaction location information for block one transactions.
|
||||||
var blockOneTxLocs = []TxLoc{
|
var blockOneTxLocs = []TxLoc{
|
||||||
{TxStart: 85, TxLen: 138},
|
{TxStart: 85, TxLen: 142},
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/daglabs/btcd/chaincfg/chainhash"
|
"github.com/daglabs/btcd/chaincfg/chainhash"
|
||||||
@ -19,7 +20,7 @@ const (
|
|||||||
|
|
||||||
// MaxTxInSequenceNum is the maximum sequence number the sequence field
|
// MaxTxInSequenceNum is the maximum sequence number the sequence field
|
||||||
// of a transaction input can be.
|
// of a transaction input can be.
|
||||||
MaxTxInSequenceNum uint32 = 0xffffffff
|
MaxTxInSequenceNum uint64 = math.MaxUint64
|
||||||
|
|
||||||
// MaxPrevOutIndex is the maximum index the index field of a previous
|
// MaxPrevOutIndex is the maximum index the index field of a previous
|
||||||
// outpoint can be.
|
// outpoint can be.
|
||||||
@ -187,16 +188,16 @@ func (o OutPoint) String() string {
|
|||||||
type TxIn struct {
|
type TxIn struct {
|
||||||
PreviousOutPoint OutPoint
|
PreviousOutPoint OutPoint
|
||||||
SignatureScript []byte
|
SignatureScript []byte
|
||||||
Sequence uint32
|
Sequence uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// SerializeSize returns the number of bytes it would take to serialize the
|
// SerializeSize returns the number of bytes it would take to serialize the
|
||||||
// the transaction input.
|
// the transaction input.
|
||||||
func (t *TxIn) SerializeSize() int {
|
func (t *TxIn) SerializeSize() int {
|
||||||
// Outpoint Hash 32 bytes + Outpoint Index 4 bytes + Sequence 4 bytes +
|
// Outpoint Hash 32 bytes + Outpoint Index 4 bytes + Sequence 8 bytes +
|
||||||
// serialized varint size for the length of SignatureScript +
|
// serialized varint size for the length of SignatureScript +
|
||||||
// SignatureScript bytes.
|
// SignatureScript bytes.
|
||||||
return 40 + VarIntSerializeSize(uint64(len(t.SignatureScript))) +
|
return 44 + VarIntSerializeSize(uint64(len(t.SignatureScript))) +
|
||||||
len(t.SignatureScript)
|
len(t.SignatureScript)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +245,7 @@ type MsgTx struct {
|
|||||||
Version int32
|
Version int32
|
||||||
TxIn []*TxIn
|
TxIn []*TxIn
|
||||||
TxOut []*TxOut
|
TxOut []*TxOut
|
||||||
LockTime int64
|
LockTime uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTxIn adds a transaction input to the message.
|
// AddTxIn adds a transaction input to the message.
|
||||||
@ -431,7 +432,7 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64LockTime, err := binarySerializer.Uint64(r, littleEndian)
|
uint64LockTime, err := binarySerializer.Uint64(r, littleEndian)
|
||||||
msg.LockTime = int64(uint64LockTime)
|
msg.LockTime = uint64LockTime
|
||||||
if err != nil {
|
if err != nil {
|
||||||
returnScriptBuffers()
|
returnScriptBuffers()
|
||||||
return err
|
return err
|
||||||
@ -727,7 +728,7 @@ func writeTxIn(w io.Writer, pver uint32, version int32, ti *TxIn) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return binarySerializer.PutUint32(w, littleEndian, ti.Sequence)
|
return binarySerializer.PutUint64(w, littleEndian, ti.Sequence)
|
||||||
}
|
}
|
||||||
|
|
||||||
// readTxOut reads the next sequence of bytes from r as a transaction output
|
// readTxOut reads the next sequence of bytes from r as a transaction output
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ func TestTx(t *testing.T) {
|
|||||||
// TestTxHash tests the ability to generate the hash of a transaction accurately.
|
// TestTxHash tests the ability to generate the hash of a transaction accurately.
|
||||||
func TestTxHash(t *testing.T) {
|
func TestTxHash(t *testing.T) {
|
||||||
// Hash of first transaction from block 113875.
|
// Hash of first transaction from block 113875.
|
||||||
hashStr := "a16521abfbac8dc484301bb57adc13ac72f71d42459c9c29c96b11972af2475c"
|
hashStr := "768f7e5de1e0a209c9f4e89a5b610d15e888dfe8f32be7f92462edc5815fc025"
|
||||||
wantHash, err := chainhash.NewHashFromStr(hashStr)
|
wantHash, err := chainhash.NewHashFromStr(hashStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("NewHashFromStr: %v", err)
|
t.Errorf("NewHashFromStr: %v", err)
|
||||||
@ -143,7 +144,7 @@ func TestTxHash(t *testing.T) {
|
|||||||
Index: 0xffffffff,
|
Index: 0xffffffff,
|
||||||
},
|
},
|
||||||
SignatureScript: []byte{0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62},
|
SignatureScript: []byte{0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62},
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
}
|
}
|
||||||
txOut := TxOut{
|
txOut := TxOut{
|
||||||
Value: 5000000000,
|
Value: 5000000000,
|
||||||
@ -334,15 +335,15 @@ func TestTxWireErrors(t *testing.T) {
|
|||||||
// Force error in transaction input sequence.
|
// Force error in transaction input sequence.
|
||||||
{multiTx, multiTxEncoded, pver, 49, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, pver, 49, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in number of transaction outputs.
|
// Force error in number of transaction outputs.
|
||||||
{multiTx, multiTxEncoded, pver, 53, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, pver, 57, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in transaction output value.
|
// Force error in transaction output value.
|
||||||
{multiTx, multiTxEncoded, pver, 54, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, pver, 58, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in transaction output pk script length.
|
// Force error in transaction output pk script length.
|
||||||
{multiTx, multiTxEncoded, pver, 62, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, pver, 66, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in transaction output pk script.
|
// Force error in transaction output pk script.
|
||||||
{multiTx, multiTxEncoded, pver, 63, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, pver, 67, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in transaction output lock time.
|
// Force error in transaction output lock time.
|
||||||
{multiTx, multiTxEncoded, pver, 206, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, pver, 210, io.ErrShortWrite, io.EOF},
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Running %d tests", len(tests))
|
t.Logf("Running %d tests", len(tests))
|
||||||
@ -477,15 +478,15 @@ func TestTxSerializeErrors(t *testing.T) {
|
|||||||
// Force error in transaction input sequence.
|
// Force error in transaction input sequence.
|
||||||
{multiTx, multiTxEncoded, 49, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, 49, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in number of transaction outputs.
|
// Force error in number of transaction outputs.
|
||||||
{multiTx, multiTxEncoded, 53, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, 57, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in transaction output value.
|
// Force error in transaction output value.
|
||||||
{multiTx, multiTxEncoded, 54, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, 58, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in transaction output pk script length.
|
// Force error in transaction output pk script length.
|
||||||
{multiTx, multiTxEncoded, 62, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, 66, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in transaction output pk script.
|
// Force error in transaction output pk script.
|
||||||
{multiTx, multiTxEncoded, 63, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, 67, io.ErrShortWrite, io.EOF},
|
||||||
// Force error in transaction output lock time.
|
// Force error in transaction output lock time.
|
||||||
{multiTx, multiTxEncoded, 206, io.ErrShortWrite, io.EOF},
|
{multiTx, multiTxEncoded, 210, io.ErrShortWrite, io.EOF},
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Running %d tests", len(tests))
|
t.Logf("Running %d tests", len(tests))
|
||||||
@ -575,7 +576,7 @@ func TestTxOverflowErrors(t *testing.T) {
|
|||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Previous output hash
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Previous output hash
|
||||||
0xff, 0xff, 0xff, 0xff, // Prevous output index
|
0xff, 0xff, 0xff, 0xff, // Prevous output index
|
||||||
0x00, // Varint for length of signature script
|
0x00, // Varint for length of signature script
|
||||||
0xff, 0xff, 0xff, 0xff, // Sequence
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Sequence
|
||||||
0x01, // Varint for number of output transactions
|
0x01, // Varint for number of output transactions
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Transaction amount
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Transaction amount
|
||||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||||
@ -622,7 +623,7 @@ func TestTxSerializeSize(t *testing.T) {
|
|||||||
{noTx, 14},
|
{noTx, 14},
|
||||||
|
|
||||||
// Transcaction with an input and an output.
|
// Transcaction with an input and an output.
|
||||||
{multiTx, 214},
|
{multiTx, 218},
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Running %d tests", len(tests))
|
t.Logf("Running %d tests", len(tests))
|
||||||
@ -648,7 +649,7 @@ var multiTx = &MsgTx{
|
|||||||
SignatureScript: []byte{
|
SignatureScript: []byte{
|
||||||
0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62,
|
0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62,
|
||||||
},
|
},
|
||||||
Sequence: 0xffffffff,
|
Sequence: math.MaxUint64,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TxOut: []*TxOut{
|
TxOut: []*TxOut{
|
||||||
@ -700,7 +701,7 @@ var multiTxEncoded = []byte{
|
|||||||
0xff, 0xff, 0xff, 0xff, // Prevous output index
|
0xff, 0xff, 0xff, 0xff, // Prevous output index
|
||||||
0x07, // Varint for length of signature script
|
0x07, // Varint for length of signature script
|
||||||
0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62, // Signature script
|
0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62, // Signature script
|
||||||
0xff, 0xff, 0xff, 0xff, // Sequence
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Sequence
|
||||||
0x02, // Varint for number of output transactions
|
0x02, // Varint for number of output transactions
|
||||||
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
|
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
|
||||||
0x43, // Varint for length of pk script
|
0x43, // Varint for length of pk script
|
||||||
@ -733,4 +734,4 @@ var multiTxEncoded = []byte{
|
|||||||
|
|
||||||
// multiTxPkScriptLocs is the location information for the public key scripts
|
// multiTxPkScriptLocs is the location information for the public key scripts
|
||||||
// located in multiTx.
|
// located in multiTx.
|
||||||
var multiTxPkScriptLocs = []int{63, 139}
|
var multiTxPkScriptLocs = []int{67, 143}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user