OSDN Git Service

BTM asset id should be define in the consensus folder
authorpaladz <453256728@qq.com>
Fri, 22 Sep 2017 05:54:46 +0000 (13:54 +0800)
committerpaladz <453256728@qq.com>
Fri, 22 Sep 2017 05:54:46 +0000 (13:54 +0800)
consensus/general.go
mining/mining.go
protocol/bc/legacy/map_test.go
protocol/mempool_test.go
protocol/validation/validation.go
protocol/validation/validation_test.go

index 1b00381..ead46c9 100644 (file)
@@ -7,7 +7,7 @@ import (
 )
 
 const (
-       //define the Max transaction size and Max block size
+       // define the Max transaction size and Max block size
        MaxTxSize    = uint64(1024)
        MaxBlockSzie = uint64(16384)
 
@@ -16,6 +16,14 @@ const (
        baseSubsidy              = uint64(624000000000)
 )
 
+// define the BTM asset id, the soul asset of Bytom
+var BTMAssetID = &bc.AssetID{
+       V0: uint64(18446744073709551615),
+       V1: uint64(18446744073709551615),
+       V2: uint64(18446744073709551615),
+       V3: uint64(18446744073709551615),
+}
+
 // HashToBig converts a *bc.Hash into a big.Int that can be used to
 // perform math comparisons.
 func HashToBig(hash *bc.Hash) *big.Int {
index 131a722..ffbd858 100644 (file)
@@ -40,7 +40,7 @@ func createCoinbaseTx(amount uint64, blockHeight uint64, addr []byte) (*legacy.T
        }
 
        builder := txbuilder.NewBuilder(time.Now())
-       builder.AddOutput(legacy.NewTxOutput(*validation.BTMAssetID, amount, cbScript, nil))
+       builder.AddOutput(legacy.NewTxOutput(*consensus.BTMAssetID, amount, cbScript, nil))
        _, txData, err := builder.Build()
        tx := &legacy.Tx{
                TxData: *txData,
index bc82270..88d55a2 100644 (file)
@@ -1,13 +1,13 @@
 package legacy
 
 import (
+       "blockchain/consensus"
        "bytes"
        "testing"
 
        "github.com/davecgh/go-spew/spew"
 
        "github.com/bytom/protocol/bc"
-       "github.com/bytom/protocol/validation"
 )
 
 func TestMapTx(t *testing.T) {
@@ -69,7 +69,7 @@ func TestMapCoinbaseTx(t *testing.T) {
                Version: 1,
                Inputs:  []*TxInput{},
                Outputs: []*TxOutput{
-                       NewTxOutput(*validation.BTMAssetID, 800000000000, []byte{1}, nil),
+                       NewTxOutput(*consensus.BTMAssetID, 800000000000, []byte{1}, nil),
                },
        }
        oldOut := oldTx.Outputs[0]
index a19e32b..5180df4 100644 (file)
@@ -1,10 +1,10 @@
 package protocol
 
 import (
+       "blockchain/consensus"
        "testing"
 
        "github.com/bytom/protocol/bc/legacy"
-       "github.com/bytom/protocol/validation"
 )
 
 func TestTxPool(t *testing.T) {
@@ -53,7 +53,7 @@ func mockCoinbaseTx(serializedSize uint64, amount uint64) *legacy.Tx {
        oldTx := &legacy.TxData{
                SerializedSize: serializedSize,
                Outputs: []*legacy.TxOutput{
-                       legacy.NewTxOutput(*validation.BTMAssetID, amount, []byte{1}, nil),
+                       legacy.NewTxOutput(*consensus.BTMAssetID, amount, []byte{1}, nil),
                },
        }
 
index d6d95d9..16d38a6 100644 (file)
@@ -16,13 +16,6 @@ const (
        gasRate         = int64(1000)
 )
 
-var BTMAssetID = &bc.AssetID{
-       V0: uint64(18446744073709551615),
-       V1: uint64(18446744073709551615),
-       V2: uint64(18446744073709551615),
-       V3: uint64(18446744073709551615),
-}
-
 type gasState struct {
        gasLeft  int64
        gasUsed  int64
@@ -151,7 +144,7 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
                        return errWrongCoinbaseTransaction
                }
 
-               if *e.WitnessDestination.Value.AssetId != *BTMAssetID {
+               if *e.WitnessDestination.Value.AssetId != *consensus.BTMAssetID {
                        return errWrongCoinbaseAsset
                }
 
@@ -185,7 +178,7 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
                        parity[*dest.Value.AssetId] = diff
                }
 
-               if amount, ok := parity[*BTMAssetID]; ok {
+               if amount, ok := parity[*consensus.BTMAssetID]; ok {
                        if err = vs.gas.setGas(amount); err != nil {
                                return err
                        }
@@ -194,7 +187,7 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
                }
 
                for assetID, amount := range parity {
-                       if amount != 0 && assetID != *BTMAssetID {
+                       if amount != 0 && assetID != *consensus.BTMAssetID {
                                return errors.WithDetailf(errUnbalanced, "asset %x sources - destinations = %d (should be 0)", assetID.Bytes(), amount)
                        }
                }
index 4eb91cc..9ac3bd7 100644 (file)
@@ -1,6 +1,7 @@
 package validation
 
 import (
+       "blockchain/consensus"
        "fmt"
        "math"
        "testing"
@@ -10,7 +11,6 @@ import (
        "github.com/bytom/errors"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/legacy"
-       "github.com/bytom/protocol/validation"
        "github.com/bytom/protocol/vm"
        "github.com/bytom/testutil"
 
@@ -678,13 +678,13 @@ func mockBlock() *bc.Block {
 func mockCoinbaseTx(amount uint64) *bc.Tx {
        return legacy.MapTx(&legacy.TxData{
                Outputs: []*legacy.TxOutput{
-                       legacy.NewTxOutput(*BTMAssetID, amount, []byte{1}, nil),
+                       legacy.NewTxOutput(*consensus.BTMAssetID, amount, []byte{1}, nil),
                },
        })
 }
 
 func mockGasTxInput() *legacy.TxInput {
-       return legacy.NewSpendInput([][]byte{}, *newHash(8), *validation.BTMAssetID, 100000000, 0, []byte{byte(vm.OP_TRUE)}, *newHash(9), []byte{})
+       return legacy.NewSpendInput([][]byte{}, *newHash(8), *consensus.BTMAssetID, 100000000, 0, []byte{byte(vm.OP_TRUE)}, *newHash(9), []byte{})
 }
 
 // Like errors.Root, but also unwraps vm.Error objects.