change txId to txID

pull/75/head
Minh Doan 6 years ago
parent 7513a79c32
commit 9f9607f5c5
  1. 10
      blockchain/block.go
  2. 4
      blockchain/blockchain.go
  3. 8
      blockchain/utxopool.go
  4. 12
      client/txgen/main.go
  5. 8
      client/wallet/main.go
  6. 10
      node/node_handler.go
  7. 4
      proto/node/node.go

@ -77,8 +77,8 @@ func (b *Block) String() string {
func (b *Block) generateMerkleRootData() { func (b *Block) generateMerkleRootData() {
var data [][]byte var data [][]byte
for _, txId := range b.TransactionIds { for _, txID := range b.TransactionIds {
data = append(data, txId[:]) data = append(data, txID[:])
} }
merkleTre := NewMerkleTree(data) merkleTre := NewMerkleTree(data)
b.MerkleRootData = merkleTre.RootNode.Data b.MerkleRootData = merkleTre.RootNode.Data
@ -115,12 +115,12 @@ func (b *Block) CalculateBlockHash() []byte {
// NewBlock creates and returns a new block. // NewBlock creates and returns a new block.
func NewBlock(transactions []*Transaction, prevBlockHash [32]byte, shardID uint32) *Block { func NewBlock(transactions []*Transaction, prevBlockHash [32]byte, shardID uint32) *Block {
numTxs := int32(len(transactions)) numTxs := int32(len(transactions))
var txIds [][32]byte var txIDs [][32]byte
for _, tx := range transactions { for _, tx := range transactions {
txIds = append(txIds, tx.ID) txIDs = append(txIDs, tx.ID)
} }
block := &Block{Timestamp: time.Now().Unix(), PrevBlockHash: prevBlockHash, NumTransactions: numTxs, TransactionIds: txIds, Transactions: transactions, ShardID: shardID, Hash: [32]byte{}} block := &Block{Timestamp: time.Now().Unix(), PrevBlockHash: prevBlockHash, NumTransactions: numTxs, TransactionIds: txIDs, Transactions: transactions, ShardID: shardID, Hash: [32]byte{}}
copy(block.Hash[:], block.CalculateBlockHash()[:]) copy(block.Hash[:], block.CalculateBlockHash()[:])
return block return block

@ -124,8 +124,8 @@ func (bc *Blockchain) FindSpendableOutputs(address [20]byte, amount int) (int, m
accumulated := 0 accumulated := 0
Work: Work:
for txId, txOutputs := range unspentUtxos { for txID, txOutputs := range unspentUtxos {
txID := hex.EncodeToString(txId[:]) txID := hex.EncodeToString(txID[:])
for outIdx, txOutput := range txOutputs { for outIdx, txOutput := range txOutputs {
if txOutput.Address == address && accumulated < amount { if txOutput.Address == address && accumulated < amount {

@ -29,11 +29,11 @@ type UTXOPool struct {
/* /*
The 3-d map's structure: The 3-d map's structure:
address - [ address - [
txId1 - [ txID1 - [
outputIndex1 - value1 outputIndex1 - value1
outputIndex2 - value2 outputIndex2 - value2
] ]
txId2 - [ txID2 - [
outputIndex1 - value1 outputIndex1 - value1
outputIndex2 - value2 outputIndex2 - value2
] ]
@ -554,8 +554,8 @@ func (utxoPool *UTXOPool) CountNumOfLockedUtxos() int {
func countNumOfUtxos(utxos *UtxoMap) int { func countNumOfUtxos(utxos *UtxoMap) int {
countAll := 0 countAll := 0
for _, utxoMap := range *utxos { for _, utxoMap := range *utxos {
for txIdStr, val := range utxoMap { for txIDStr, val := range utxoMap {
_, err := hex.DecodeString(txIdStr) _, err := hex.DecodeString(txIDStr)
if err != nil { if err != nil {
continue continue
} }

@ -79,11 +79,11 @@ func generateSimulatedTransactions(subsetId, numSubset int, shardID int, dataNod
/* /*
UTXO map structure: UTXO map structure:
address - [ address - [
txId1 - [ txID1 - [
outputIndex1 - value1 outputIndex1 - value1
outputIndex2 - value2 outputIndex2 - value2
] ]
txId2 - [ txID2 - [
outputIndex1 - value1 outputIndex1 - value1
outputIndex2 - value2 outputIndex2 - value2
] ]
@ -100,16 +100,16 @@ UTXOLOOP:
for address, txMap := range dataNodes[shardID].UtxoPool.UtxoMap { for address, txMap := range dataNodes[shardID].UtxoPool.UtxoMap {
if int(binary.BigEndian.Uint32(address[:]))%numSubset == subsetId%numSubset { // Work on one subset of utxo at a time if int(binary.BigEndian.Uint32(address[:]))%numSubset == subsetId%numSubset { // Work on one subset of utxo at a time
txInfo.address = address txInfo.address = address
// Loop over all txIds for the address // Loop over all txIDs for the address
for txIdStr, utxoMap := range txMap { for txIDStr, utxoMap := range txMap {
// Parse TxId // Parse TxId
id, err := hex.DecodeString(txIdStr) id, err := hex.DecodeString(txIDStr)
if err != nil { if err != nil {
continue continue
} }
copy(txInfo.id[:], id[:]) copy(txInfo.id[:], id[:])
// Loop over all utxos for the txId // Loop over all utxos for the txID
utxoSize := len(utxoMap) utxoSize := len(utxoMap)
batchSize := utxoSize / numSubset batchSize := utxoSize / numSubset
i := subsetId % numSubset i := subsetId % numSubset

@ -174,15 +174,15 @@ func main() {
txInputs := []blockchain.TXInput{} txInputs := []blockchain.TXInput{}
LOOP: LOOP:
for shardID, utxoMap := range shardUtxoMap { for shardID, utxoMap := range shardUtxoMap {
for txId, vout2AmountMap := range utxoMap[senderAddressBytes] { for txID, vout2AmountMap := range utxoMap[senderAddressBytes] {
txIdBytes, err := utils.Get32BytesFromString(txId) txIDBytes, err := utils.Get32BytesFromString(txID)
if err != nil { if err != nil {
fmt.Println("Failed to parse txId") fmt.Println("Failed to parse txID")
continue continue
} }
for voutIndex, utxoAmount := range vout2AmountMap { for voutIndex, utxoAmount := range vout2AmountMap {
cummulativeBalance += utxoAmount cummulativeBalance += utxoAmount
txIn := blockchain.NewTXInput(blockchain.NewOutPoint(&txIdBytes, voutIndex), senderAddressBytes, shardID) txIn := blockchain.NewTXInput(blockchain.NewOutPoint(&txIDBytes, voutIndex), senderAddressBytes, shardID)
txInputs = append(txInputs, *txIn) txInputs = append(txInputs, *txIn)
if cummulativeBalance >= amount { if cummulativeBalance >= amount {
break LOOP break LOOP

@ -244,7 +244,7 @@ func (node *Node) transactionMessageHandler(msgPayload []byte) {
node.addPendingTransactions(*txList) node.addPendingTransactions(*txList)
case proto_node.REQUEST: case proto_node.REQUEST:
reader := bytes.NewBuffer(msgPayload[1:]) reader := bytes.NewBuffer(msgPayload[1:])
var txIds map[[32]byte]bool var txIDs map[[32]byte]bool
buf := make([]byte, 32) // 32 byte hash Id buf := make([]byte, 32) // 32 byte hash Id
for { for {
_, err := reader.Read(buf) _, err := reader.Read(buf)
@ -252,14 +252,14 @@ func (node *Node) transactionMessageHandler(msgPayload []byte) {
break break
} }
var txId [32]byte var txID [32]byte
copy(txId[:], buf) copy(txID[:], buf)
txIds[txId] = true txIDs[txID] = true
} }
var txToReturn []*blockchain.Transaction var txToReturn []*blockchain.Transaction
for _, tx := range node.pendingTransactions { for _, tx := range node.pendingTransactions {
if txIds[tx.ID] { if txIDs[tx.ID] {
txToReturn = append(txToReturn, tx) txToReturn = append(txToReturn, tx)
} }
} }

@ -155,8 +155,8 @@ func ConstructRequestTransactionsMessage(transactionIds [][]byte) []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(proto.NODE)}) byteBuffer := bytes.NewBuffer([]byte{byte(proto.NODE)})
byteBuffer.WriteByte(byte(TRANSACTION)) byteBuffer.WriteByte(byte(TRANSACTION))
byteBuffer.WriteByte(byte(REQUEST)) byteBuffer.WriteByte(byte(REQUEST))
for _, txId := range transactionIds { for _, txID := range transactionIds {
byteBuffer.Write(txId) byteBuffer.Write(txID)
} }
return byteBuffer.Bytes() return byteBuffer.Bytes()
} }

Loading…
Cancel
Save