Skip to content

Commit

Permalink
Add WithdrawExpireUnfreeze transaction processing
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Sep 11, 2023
1 parent 272d155 commit c22dfad
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/tron/TronEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
asTRXTransferContract,
asUnfreezeBalanceContract,
asUnfreezeV2BalanceContract,
asWithdrawExpireUnfreezeContract,
CalcTxFeeOpts,
ReferenceBlock,
SafeTronWalletInfo,
Expand Down Expand Up @@ -705,6 +706,50 @@ export class TronEngine extends CurrencyEngine<TronTools, SafeTronWalletInfo> {
this.addTransaction(currencyCode, edgeTransaction)
return out
}

// Parse WithdrawExpireUnfreeze transactions
const withdrawExpireUnfreezeTransaction = asMaybe(
asWithdrawExpireUnfreezeContract
)(contract)
if (withdrawExpireUnfreezeTransaction != null) {
const {
parameter: {
value: { owner_address: fromAddress }
}
} = withdrawExpireUnfreezeTransaction

if (
hexToBase58Address(fromAddress) !== this.walletLocalData.publicKey
) {
break
}

const feeNativeAmount = retArray[0].fee.toString()
const { currencyCode } = this.currencyInfo

// The withdrawn amount isn't included in this object. We only know it if we created the TX.
const sentTx = this.transactionList[currencyCode].find(
edgeTx => edgeTx.txid === txid
)
if (sentTx == null) break
const nativeAmount = sentTx.nativeAmount

const edgeTransaction: EdgeTransaction = {
txid,
date: Math.floor(timestamp / 1000),
currencyCode,
blockHeight: blockNumber,
nativeAmount,
isSend: false,
networkFee: feeNativeAmount,
ourReceiveAddresses,
signedTx: '',
walletId: this.walletId
}

this.addTransaction(currencyCode, edgeTransaction)
return out
}
}
return out
}
Expand Down
9 changes: 9 additions & 0 deletions src/tron/tronTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,15 @@ export const asUnfreezeV2BalanceContract = asObject({
type: asValue('UnfreezeBalanceV2Contract')
})

export const asWithdrawExpireUnfreezeContract = asObject({
parameter: asObject({
value: asObject({
owner_address: asString
})
}),
type: asValue('WithdrawExpireUnfreezeContract')
})

export interface TronGridQuery<T> {
data: T[]
success: boolean
Expand Down

0 comments on commit c22dfad

Please sign in to comment.