add SatoshiPerBitcent constant and export SatoshiPerBitcoin and

MaxSatoshi
This commit is contained in:
David Hill 2013-10-29 14:57:31 -04:00
parent 6165e9b95b
commit 8271a11808

View file

@ -16,11 +16,14 @@ import (
) )
const ( const (
// satoshiPerBitcoin is the number of satoshi in one bitcoin (1 BTC). // SatoshiPerBitcent is the number of satoshi in one bitcoin cent.
satoshiPerBitcoin int64 = 1e8 SatoshiPerBitcent int64 = 1e6
// maxSatoshi is the maximum transaction amount allowed in satoshi. // SatoshiPerBitcoin is the number of satoshi in one bitcoin (1 BTC).
maxSatoshi int64 = 21e6 * satoshiPerBitcoin SatoshiPerBitcoin int64 = 1e8
// MaxSatoshi is the maximum transaction amount allowed in satoshi.
MaxSatoshi int64 = 21e6 * SatoshiPerBitcoin
// maxSigOpsPerBlock is the maximum number of signature operations // maxSigOpsPerBlock is the maximum number of signature operations
// allowed for a block. It is a fraction of the max block payload size. // allowed for a block. It is a fraction of the max block payload size.
@ -49,7 +52,7 @@ const (
// baseSubsidy is the starting subsidy amount for mined blocks. This // baseSubsidy is the starting subsidy amount for mined blocks. This
// value is halved every subsidyHalvingInterval blocks. // value is halved every subsidyHalvingInterval blocks.
baseSubsidy = 50 * satoshiPerBitcoin baseSubsidy = 50 * SatoshiPerBitcoin
// subsidyHalvingInterval is the interval of blocks at which the // subsidyHalvingInterval is the interval of blocks at which the
// baseSubsidy is continually halved. See calcBlockSubsidy for more // baseSubsidy is continually halved. See calcBlockSubsidy for more
@ -201,7 +204,7 @@ func CheckTransactionSanity(tx *btcutil.Tx) error {
// transaction. Also, the total of all outputs must abide by the same // transaction. Also, the total of all outputs must abide by the same
// restrictions. All amounts in a transaction are in a unit value known // restrictions. All amounts in a transaction are in a unit value known
// as a satoshi. One bitcoin is a quantity of satoshi as defined by the // as a satoshi. One bitcoin is a quantity of satoshi as defined by the
// satoshiPerBitcoin constant. // SatoshiPerBitcoin constant.
var totalSatoshi int64 var totalSatoshi int64
for _, txOut := range msgTx.TxOut { for _, txOut := range msgTx.TxOut {
satoshi := txOut.Value satoshi := txOut.Value
@ -210,10 +213,10 @@ func CheckTransactionSanity(tx *btcutil.Tx) error {
"value of %v", satoshi) "value of %v", satoshi)
return RuleError(str) return RuleError(str)
} }
if satoshi > maxSatoshi { if satoshi > MaxSatoshi {
str := fmt.Sprintf("transaction output value of %v is "+ str := fmt.Sprintf("transaction output value of %v is "+
"higher than max allowed value of %v", satoshi, "higher than max allowed value of %v", satoshi,
maxSatoshi) MaxSatoshi)
return RuleError(str) return RuleError(str)
} }
@ -226,10 +229,10 @@ func CheckTransactionSanity(tx *btcutil.Tx) error {
"outputs has negative value of %v", totalSatoshi) "outputs has negative value of %v", totalSatoshi)
return RuleError(str) return RuleError(str)
} }
if totalSatoshi > maxSatoshi { if totalSatoshi > MaxSatoshi {
str := fmt.Sprintf("total value of all transaction "+ str := fmt.Sprintf("total value of all transaction "+
"outputs is %v which is higher than max "+ "outputs is %v which is higher than max "+
"allowed value of %v", totalSatoshi, maxSatoshi) "allowed value of %v", totalSatoshi, MaxSatoshi)
return RuleError(str) return RuleError(str)
} }
} }
@ -652,17 +655,17 @@ func CheckTransactionInputs(tx *btcutil.Tx, txHeight int64, txStore TxStore) (in
// or more than the max allowed per transaction. All amounts in // or more than the max allowed per transaction. All amounts in
// a transaction are in a unit value known as a satoshi. One // a transaction are in a unit value known as a satoshi. One
// bitcoin is a quantity of satoshi as defined by the // bitcoin is a quantity of satoshi as defined by the
// satoshiPerBitcoin constant. // SatoshiPerBitcoin constant.
originTxSatoshi := originTx.Tx.MsgTx().TxOut[originTxIndex].Value originTxSatoshi := originTx.Tx.MsgTx().TxOut[originTxIndex].Value
if originTxSatoshi < 0 { if originTxSatoshi < 0 {
str := fmt.Sprintf("transaction output has negative "+ str := fmt.Sprintf("transaction output has negative "+
"value of %v", originTxSatoshi) "value of %v", originTxSatoshi)
return 0, RuleError(str) return 0, RuleError(str)
} }
if originTxSatoshi > maxSatoshi { if originTxSatoshi > MaxSatoshi {
str := fmt.Sprintf("transaction output value of %v is "+ str := fmt.Sprintf("transaction output value of %v is "+
"higher than max allowed value of %v", "higher than max allowed value of %v",
originTxSatoshi, maxSatoshi) originTxSatoshi, MaxSatoshi)
return 0, RuleError(str) return 0, RuleError(str)
} }
@ -671,11 +674,11 @@ func CheckTransactionInputs(tx *btcutil.Tx, txHeight int64, txStore TxStore) (in
// the accumulator so check for overflow. // the accumulator so check for overflow.
lastSatoshiIn := totalSatoshiIn lastSatoshiIn := totalSatoshiIn
totalSatoshiIn += originTxSatoshi totalSatoshiIn += originTxSatoshi
if totalSatoshiIn < lastSatoshiIn || totalSatoshiIn > maxSatoshi { if totalSatoshiIn < lastSatoshiIn || totalSatoshiIn > MaxSatoshi {
str := fmt.Sprintf("total value of all transaction "+ str := fmt.Sprintf("total value of all transaction "+
"inputs is %v which is higher than max "+ "inputs is %v which is higher than max "+
"allowed value of %v", totalSatoshiIn, "allowed value of %v", totalSatoshiIn,
maxSatoshi) MaxSatoshi)
return 0, RuleError(str) return 0, RuleError(str)
} }