Skip to content

Instantly share code, notes, and snippets.

@shortthefomo
Last active November 5, 2022 01:35
Show Gist options
  • Save shortthefomo/5d28929964e9a306ca809824824a949a to your computer and use it in GitHub Desktop.
Save shortthefomo/5d28929964e9a306ca809824824a949a to your computer and use it in GitHub Desktop.
XTPL NFT deriveSale
//pass tx as returned from ledger
ntfDeriveSale(tx) {
let hash = tx.hash || tx.transaction.hash
let trade = {}
let taker = tx.Account
for(let affected of (tx.meta || tx.metaData).AffectedNodes){
let node = affected.DeletedNode
if(!node || node.LedgerEntryType !== 'NFTokenOffer')
continue
let destination = node.FinalFields.Destination || tx.Account
let maker = node.FinalFields.Owner
let paid = this.fromLedgerAmount(node.FinalFields.Amount)
let id = node.FinalFields.NFTokenID
trade = {
id,
hash,
taker,
maker,
destination,
paid
}
if (!node.FinalFields.Destination) {
taker = node.FinalFields.Owner
continue
}
}
console.log('NFT trade', trade)
return trade
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment