|
|
@ -155,51 +155,51 @@ func generateCrossShardTx(txInfo *TxInfo) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
crossShardNode := txInfo.dataNodes[crossShardId] |
|
|
|
//crossShardNode := txInfo.dataNodes[crossShardId]
|
|
|
|
crossShardUtxosMap := crossShardNode.UtxoPool.UtxoMap[txInfo.address] |
|
|
|
//crossShardUtxosMap := crossShardNode.UtxoPool.UtxoMap[txInfo.address]
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the cross shard utxo from another shard
|
|
|
|
//// Get the cross shard utxo from another shard
|
|
|
|
var crossTxin *blockchain.TXInput |
|
|
|
//var crossTxin *blockchain.TXInput
|
|
|
|
crossUtxoValue := 0 |
|
|
|
//crossUtxoValue := 0
|
|
|
|
// Loop over utxos for the same address from the other shard and use the first utxo as the second cross tx input
|
|
|
|
//// Loop over utxos for the same address from the other shard and use the first utxo as the second cross tx input
|
|
|
|
for crossTxIdStr, crossShardUtxos := range crossShardUtxosMap { |
|
|
|
//for crossTxIdStr, crossShardUtxos := range crossShardUtxosMap {
|
|
|
|
// Parse TxId
|
|
|
|
// // Parse TxId
|
|
|
|
id, err := hex.DecodeString(crossTxIdStr) |
|
|
|
// id, err := hex.DecodeString(crossTxIdStr)
|
|
|
|
if err != nil { |
|
|
|
// if err != nil {
|
|
|
|
continue |
|
|
|
// continue
|
|
|
|
} |
|
|
|
// }
|
|
|
|
crossTxId := [32]byte{} |
|
|
|
// crossTxId := [32]byte{}
|
|
|
|
copy(crossTxId[:], id[:]) |
|
|
|
// copy(crossTxId[:], id[:])
|
|
|
|
|
|
|
|
//
|
|
|
|
for crossShardIndex, crossShardValue := range crossShardUtxos { |
|
|
|
// for crossShardIndex, crossShardValue := range crossShardUtxos {
|
|
|
|
crossUtxoValue = crossShardValue |
|
|
|
// crossUtxoValue = crossShardValue
|
|
|
|
crossTxin = blockchain.NewTXInput(blockchain.NewOutPoint(&crossTxId, crossShardIndex), txInfo.address, crossShardId) |
|
|
|
// crossTxin = blockchain.NewTXInput(blockchain.NewOutPoint(&crossTxId, crossShardIndex), txInfo.address, crossShardId)
|
|
|
|
break |
|
|
|
// break
|
|
|
|
} |
|
|
|
// }
|
|
|
|
if crossTxin != nil { |
|
|
|
// if crossTxin != nil {
|
|
|
|
break |
|
|
|
// break
|
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
// Add the utxo from current shard
|
|
|
|
// Add the utxo from current shard
|
|
|
|
txIn := blockchain.NewTXInput(blockchain.NewOutPoint(&txInfo.id, txInfo.index), txInfo.address, nodeShardID) |
|
|
|
txIn := blockchain.NewTXInput(blockchain.NewOutPoint(&txInfo.id, txInfo.index), txInfo.address, nodeShardID) |
|
|
|
txInputs := []blockchain.TXInput{*txIn} |
|
|
|
txInputs := []blockchain.TXInput{*txIn} |
|
|
|
|
|
|
|
|
|
|
|
// Add the utxo from the other shard, if any
|
|
|
|
// Add the utxo from the other shard, if any
|
|
|
|
if crossTxin != nil { // This means the ratio of cross shard tx could be lower than 1/3
|
|
|
|
//if crossTxin != nil { // This means the ratio of cross shard tx could be lower than 1/3
|
|
|
|
txInputs = append(txInputs, *crossTxin) |
|
|
|
// txInputs = append(txInputs, *crossTxin)
|
|
|
|
} |
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
// Spend the utxo from the current shard to a random address in [0 - N)
|
|
|
|
// Spend the utxo from the current shard to a random address in [0 - N)
|
|
|
|
txout := blockchain.TXOutput{Amount: txInfo.value, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: nodeShardID} |
|
|
|
txout := blockchain.TXOutput{Amount: txInfo.value, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: crossShardId} |
|
|
|
|
|
|
|
|
|
|
|
txOutputs := []blockchain.TXOutput{txout} |
|
|
|
txOutputs := []blockchain.TXOutput{txout} |
|
|
|
|
|
|
|
|
|
|
|
// Spend the utxo from the other shard, if any, to a random address in [0 - N)
|
|
|
|
// Spend the utxo from the other shard, if any, to a random address in [0 - N)
|
|
|
|
if crossTxin != nil { |
|
|
|
//if crossTxin != nil {
|
|
|
|
crossTxout := blockchain.TXOutput{Amount: crossUtxoValue, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: crossShardId} |
|
|
|
// crossTxout := blockchain.TXOutput{Amount: crossUtxoValue, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: crossShardId}
|
|
|
|
txOutputs = append(txOutputs, crossTxout) |
|
|
|
// txOutputs = append(txOutputs, crossTxout)
|
|
|
|
} |
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
// Construct the new transaction
|
|
|
|
// Construct the new transaction
|
|
|
|
tx := blockchain.Transaction{ID: [32]byte{}, TxInput: txInputs, TxOutput: txOutputs, Proofs: nil} |
|
|
|
tx := blockchain.Transaction{ID: [32]byte{}, TxInput: txInputs, TxOutput: txOutputs, Proofs: nil} |
|
|
|