@ -25,15 +25,15 @@ type UTXOPool struct {
]
]
* /
UtxoMap map [ string ] map [ string ] map [ int ] int
LockedUtxoMap map [ string ] map [ string ] map [ int ] int
UtxoMap map [ string ] map [ string ] map [ u int32 ] int
LockedUtxoMap map [ string ] map [ string ] map [ u int32 ] int
ShardId uint32
mutex sync . Mutex
}
// VerifyTransactions verifies if a list of transactions valid for this shard.
func ( utxoPool * UTXOPool ) VerifyTransactions ( transactions [ ] * Transaction ) bool {
spentTXOs := make ( map [ string ] map [ string ] map [ int ] bool )
spentTXOs := make ( map [ string ] map [ string ] map [ u int32 ] bool )
if utxoPool != nil {
for _ , tx := range transactions {
if valid , crossShard := utxoPool . VerifyOneTransaction ( tx , & spentTXOs ) ; ! crossShard && ! valid {
@ -45,13 +45,13 @@ func (utxoPool *UTXOPool) VerifyTransactions(transactions []*Transaction) bool {
}
// VerifyOneTransaction verifies if a list of transactions valid.
func ( utxoPool * UTXOPool ) VerifyOneTransaction ( tx * Transaction , spentTXOs * map [ string ] map [ string ] map [ int ] bool ) ( valid , crossShard bool ) {
func ( utxoPool * UTXOPool ) VerifyOneTransaction ( tx * Transaction , spentTXOs * map [ string ] map [ string ] map [ u int32 ] bool ) ( valid , crossShard bool ) {
if len ( tx . Proofs ) != 0 {
return utxoPool . VerifyUnlockTransaction ( tx )
}
if spentTXOs == nil {
spentTXOs = & map [ string ] map [ string ] map [ int ] bool { }
spentTXOs = & map [ string ] map [ string ] map [ u int32 ] bool { }
}
inTotal := 0
// Calculate the sum of TxInput
@ -72,10 +72,10 @@ func (utxoPool *UTXOPool) VerifyOneTransaction(tx *Transaction, spentTXOs *map[s
}
// Mark the transactions with the address and index spent.
if _ , ok := ( * spentTXOs ) [ in . Address ] ; ! ok {
( * spentTXOs ) [ in . Address ] = make ( map [ string ] map [ int ] bool )
( * spentTXOs ) [ in . Address ] = make ( map [ string ] map [ u int32 ] bool )
}
if _ , ok := ( * spentTXOs ) [ in . Address ] [ inTxID ] ; ! ok {
( * spentTXOs ) [ in . Address ] [ inTxID ] = make ( map [ int ] bool )
( * spentTXOs ) [ in . Address ] [ inTxID ] = make ( map [ u int32 ] bool )
}
( * spentTXOs ) [ in . Address ] [ inTxID ] [ index ] = true
@ -193,11 +193,11 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) {
// put the delete (locked) utxo into a separate locked utxo pool
inTxID := hex . EncodeToString ( in . PreviousOutPoint . Hash [ : ] )
if _ , ok := utxoPool . LockedUtxoMap [ in . Address ] ; ! ok {
utxoPool . LockedUtxoMap [ in . Address ] = make ( map [ string ] map [ int ] int )
utxoPool . LockedUtxoMap [ in . Address ] [ inTxID ] = make ( map [ int ] int )
utxoPool . LockedUtxoMap [ in . Address ] = make ( map [ string ] map [ u int32 ] int )
utxoPool . LockedUtxoMap [ in . Address ] [ inTxID ] = make ( map [ u int32 ] int )
}
if _ , ok := utxoPool . LockedUtxoMap [ in . Address ] [ inTxID ] ; ! ok {
utxoPool . LockedUtxoMap [ in . Address ] [ inTxID ] = make ( map [ int ] int )
utxoPool . LockedUtxoMap [ in . Address ] [ inTxID ] = make ( map [ u int32 ] int )
}
utxoPool . LockedUtxoMap [ in . Address ] [ inTxID ] [ in . PreviousOutPoint . Index ] = value
}
@ -219,11 +219,11 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) {
// Simply bring back the locked (removed) utxo
inTxID := hex . EncodeToString ( in . PreviousOutPoint . Hash [ : ] )
if _ , ok := utxoPool . UtxoMap [ in . Address ] ; ! ok {
utxoPool . UtxoMap [ in . Address ] = make ( map [ string ] map [ int ] int )
utxoPool . UtxoMap [ in . Address ] [ inTxID ] = make ( map [ int ] int )
utxoPool . UtxoMap [ in . Address ] = make ( map [ string ] map [ u int32 ] int )
utxoPool . UtxoMap [ in . Address ] [ inTxID ] = make ( map [ u int32 ] int )
}
if _ , ok := utxoPool . UtxoMap [ in . Address ] [ inTxID ] ; ! ok {
utxoPool . UtxoMap [ in . Address ] [ inTxID ] = make ( map [ int ] int )
utxoPool . UtxoMap [ in . Address ] [ inTxID ] = make ( map [ u int32 ] int )
}
value := utxoPool . LockedUtxoMap [ in . Address ] [ inTxID ] [ in . PreviousOutPoint . Index ]
utxoPool . UtxoMap [ in . Address ] [ inTxID ] [ in . PreviousOutPoint . Index ] = value
@ -239,13 +239,13 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) {
continue
}
if _ , ok := utxoPool . UtxoMap [ out . Address ] ; ! ok {
utxoPool . UtxoMap [ out . Address ] = make ( map [ string ] map [ int ] int )
utxoPool . UtxoMap [ out . Address ] [ txID ] = make ( map [ int ] int )
utxoPool . UtxoMap [ out . Address ] = make ( map [ string ] map [ u int32 ] int )
utxoPool . UtxoMap [ out . Address ] [ txID ] = make ( map [ u int32 ] int )
}
if _ , ok := utxoPool . UtxoMap [ out . Address ] [ txID ] ; ! ok {
utxoPool . UtxoMap [ out . Address ] [ txID ] = make ( map [ int ] int )
utxoPool . UtxoMap [ out . Address ] [ txID ] = make ( map [ u int32 ] int )
}
utxoPool . UtxoMap [ out . Address ] [ txID ] [ index ] = out . Value
utxoPool . UtxoMap [ out . Address ] [ txID ] [ uint32 ( index ) ] = out . Value
}
}
} // If it's a cross shard locking Tx, then don't update so the input UTXOs are locked (removed), and the money is not spendable until unlock-to-commit or unlock-to-abort
@ -275,12 +275,12 @@ func (utxoPool *UTXOPool) VerifyAndUpdate(transactions []*Transaction) bool {
func CreateUTXOPoolFromTransaction ( tx * Transaction , shardId uint32 ) * UTXOPool {
var utxoPool UTXOPool
txID := hex . EncodeToString ( tx . ID [ : ] )
utxoPool . UtxoMap = make ( map [ string ] map [ string ] map [ int ] int )
utxoPool . LockedUtxoMap = make ( map [ string ] map [ string ] map [ int ] int )
utxoPool . UtxoMap = make ( map [ string ] map [ string ] map [ u int32 ] int )
utxoPool . LockedUtxoMap = make ( map [ string ] map [ string ] map [ u int32 ] int )
for index , out := range tx . TxOutput {
utxoPool . UtxoMap [ out . Address ] = make ( map [ string ] map [ int ] int )
utxoPool . UtxoMap [ out . Address ] [ txID ] = make ( map [ int ] int )
utxoPool . UtxoMap [ out . Address ] [ txID ] [ index ] = out . Value
utxoPool . UtxoMap [ out . Address ] = make ( map [ string ] map [ u int32 ] int )
utxoPool . UtxoMap [ out . Address ] [ txID ] = make ( map [ u int32 ] int )
utxoPool . UtxoMap [ out . Address ] [ txID ] [ uint32 ( index ) ] = out . Value
}
utxoPool . ShardId = shardId
return & utxoPool
@ -296,7 +296,7 @@ func CreateUTXOPoolFromGenesisBlockChain(bc *Blockchain) *UTXOPool {
// SelectTransactionsForNewBlock returns a list of index of valid transactions for the new block.
func ( utxoPool * UTXOPool ) SelectTransactionsForNewBlock ( transactions [ ] * Transaction , maxNumTxs int ) ( [ ] * Transaction , [ ] * Transaction , [ ] * CrossShardTxAndProof ) {
selected , unselected , crossShardTxs := [ ] * Transaction { } , [ ] * Transaction { } , [ ] * CrossShardTxAndProof { }
spentTXOs := make ( map [ string ] map [ string ] map [ int ] bool )
spentTXOs := make ( map [ string ] map [ string ] map [ u int32 ] bool )
for _ , tx := range transactions {
valid , crossShard := utxoPool . VerifyOneTransaction ( tx , & spentTXOs )
@ -330,7 +330,7 @@ func getShardTxInput(transaction *Transaction, shardID uint32) []TXInput {
}
// DeleteOneBalanceItem deletes one balance item of UTXOPool and clean up if possible.
func ( utxoPool * UTXOPool ) DeleteOneUtxo ( address , txID string , index int ) {
func ( utxoPool * UTXOPool ) DeleteOneUtxo ( address , txID string , index u int32 ) {
delete ( utxoPool . UtxoMap [ address ] [ txID ] , index )
if len ( utxoPool . UtxoMap [ address ] [ txID ] ) == 0 {
delete ( utxoPool . UtxoMap [ address ] , txID )
@ -341,7 +341,7 @@ func (utxoPool *UTXOPool) DeleteOneUtxo(address, txID string, index int) {
}
// DeleteOneBalanceItem deletes one balance item of UTXOPool and clean up if possible.
func ( utxoPool * UTXOPool ) DeleteOneLockedUtxo ( address , txID string , index int ) {
func ( utxoPool * UTXOPool ) DeleteOneLockedUtxo ( address , txID string , index u int32 ) {
delete ( utxoPool . LockedUtxoMap [ address ] [ txID ] , index )
if len ( utxoPool . LockedUtxoMap [ address ] [ txID ] ) == 0 {
delete ( utxoPool . LockedUtxoMap [ address ] , txID )