Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions data/transactions/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,18 @@ func (tx Transaction) TxAmount() basics.MicroAlgos {
}
}

// GetReceiverAddress returns the address of the receiver. If the transaction has no receiver, it returns the empty address.
func (tx Transaction) GetReceiverAddress() basics.Address {
switch tx.Type {
case protocol.PaymentTx:
return tx.PaymentTxnFields.Receiver
case protocol.AssetTransferTx:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the 'Receiver' be the clawback address in case of clawback transaction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that only the sender changes. unless I'm missing something.

return tx.AssetTransferTxnFields.AssetReceiver
default:
return basics.Address{}
}
}

// EstimateEncodedSize returns the estimated encoded size of the transaction including the signature.
// This function is to be used for calculating the fee
func (tx Transaction) EstimateEncodedSize() int {
Expand Down
2 changes: 1 addition & 1 deletion node/indexer/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (idb *DB) AddBlock(b bookkeeping.Block) error {
}
for _, txad := range payset {
txn := txad.SignedTxn
_, err = stmt.Exec(txn.ID().String(), txn.Txn.Sender.String(), txn.Txn.Receiver.String(), b.Round(), b.TimeStamp)
_, err = stmt.Exec(txn.ID().String(), txn.Txn.Sender.String(), txn.Txn.GetReceiverAddress().String(), b.Round(), b.TimeStamp)
if err != nil {
return err
}
Expand Down
42 changes: 39 additions & 3 deletions node/indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,31 @@ func (s *IndexSuite) TestIndexer_DuplicateRounds() {
}
}

func (s *IndexSuite) TestIndexer_Asset() {
query := "SELECT txid from transactions where (from_addr = $1 OR to_addr = $1)"
rows, err := s.idx.IDB.dbr.Handle.Query(query, s.addrs[0].String())
require.NoError(s.T(), err)
defer rows.Close()

txids := make(map[string]bool, 0)
var txid string
for rows.Next() {
err := rows.Scan(&txid)
require.NoError(s.T(), err)
txids[txid] = true
}

// make sure all txns are in list
for _, txn := range s.txns {
if txn.Txn.Type == protocol.AssetTransferTx {
if txn.Txn.Sender == s.addrs[0] || txn.Txn.AssetReceiver == s.addrs[0] {
require.True(s.T(), txids[txn.ID().String()])
}
}
}

}

func TestExampleTestSuite(t *testing.T) {
suite.Run(t, new(IndexSuite))
}
Expand Down Expand Up @@ -201,17 +226,28 @@ func generateTestObjects(numTxs, numAccs int) ([]transactions.Transaction, []tra
exp := iss + 10

txs[i] = transactions.Transaction{
Type: protocol.PaymentTx,
Header: transactions.Header{
Sender: addresses[s],
Fee: basics.MicroAlgos{Raw: f},
FirstValid: basics.Round(iss),
LastValid: basics.Round(exp),
},
PaymentTxnFields: transactions.PaymentTxnFields{
}

// Create half assets and half payment
if i%2 == 0 {
txs[i].Type = protocol.PaymentTx
txs[i].PaymentTxnFields = transactions.PaymentTxnFields{
Receiver: addresses[r],
Amount: basics.MicroAlgos{Raw: uint64(a)},
},
}
} else {
txs[i].Type = protocol.AssetTransferTx
txs[i].AssetTransferTxnFields = transactions.AssetTransferTxnFields{
AssetReceiver: addresses[r],
AssetAmount: uint64(a),
XferAsset: basics.AssetIndex(uint64(rand.Intn(20000))),
}
}
signed[i] = txs[i].Sign(secrets[s])
}
Expand Down