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() {
var data [][]byte
for _, txId := range b.TransactionIds {
data = append(data, txId[:])
for _, txID := range b.TransactionIds {
data = append(data, txID[:])
}
merkleTre := NewMerkleTree(data)
b.MerkleRootData = merkleTre.RootNode.Data
@ -115,12 +115,12 @@ func (b *Block) CalculateBlockHash() []byte {
// NewBlock creates and returns a new block.
func NewBlock(transactions []*Transaction, prevBlockHash [32]byte, shardID uint32) *Block {
numTxs := int32(len(transactions))
var txIds [][32]byte
var txIDs [][32]byte
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()[:])
return block

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

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

@ -79,11 +79,11 @@ func generateSimulatedTransactions(subsetId, numSubset int, shardID int, dataNod
/*
UTXO map structure:
address - [
txId1 - [
txID1 - [
outputIndex1 - value1
outputIndex2 - value2
]
txId2 - [
txID2 - [
outputIndex1 - value1
outputIndex2 - value2
]
@ -100,16 +100,16 @@ UTXOLOOP:
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
txInfo.address = address
// Loop over all txIds for the address
for txIdStr, utxoMap := range txMap {
// Loop over all txIDs for the address
for txIDStr, utxoMap := range txMap {
// Parse TxId
id, err := hex.DecodeString(txIdStr)
id, err := hex.DecodeString(txIDStr)
if err != nil {
continue
}
copy(txInfo.id[:], id[:])
// Loop over all utxos for the txId
// Loop over all utxos for the txID
utxoSize := len(utxoMap)
batchSize := utxoSize / numSubset
i := subsetId % numSubset

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

@ -244,7 +244,7 @@ func (node *Node) transactionMessageHandler(msgPayload []byte) {
node.addPendingTransactions(*txList)
case proto_node.REQUEST:
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
for {
_, err := reader.Read(buf)
@ -252,14 +252,14 @@ func (node *Node) transactionMessageHandler(msgPayload []byte) {
break
}
var txId [32]byte
copy(txId[:], buf)
txIds[txId] = true
var txID [32]byte
copy(txID[:], buf)
txIDs[txID] = true
}
var txToReturn []*blockchain.Transaction
for _, tx := range node.pendingTransactions {
if txIds[tx.ID] {
if txIDs[tx.ID] {
txToReturn = append(txToReturn, tx)
}
}

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

Loading…
Cancel
Save