Looking at Pseudocode to walk the tangle?, in order to walk the tangle you look at the open tips and then you look for the parents. getTips gives you a list of all the open tips. What API call is needed however to get the parents?
1 Answer
The 2 parents of a transactions are called trunk transaction and branch transaction.
You get them like this: (It's python but the names and arguments in other libraries are very similar)
getTips
returns a list of transaction hashes
tips = api.get_tips()['hashes']
Call getTrytes
to fetch a transaction from its hash. (tips[0]
for the first transaction in tips
)
transaction_trytes = api.get_trytes([tips[0]])['trytes']
Transaction.from_tryte_string
takes the trytes and casts them into a Transaction
-object
transaction = Transaction.from_tryte_string(transaction_trytes[0])
To get the parents, use the properties of the transaction
trunkTransactionHash = transaction.trunk_transaction_hash()
branchTransactionHash = transaction.branch_transaction_hash()
Then you can call getTrytes
again
trunkTransaction = api.get_trytes([trunkTransactionHash])