Skip to content

Commit

Permalink
Add IdentityCreditWithdrawal decode
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic committed Feb 23, 2024
1 parent 831146a commit 236810a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/api/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ const decodeStateTransition = async (client, base64) => {

break
}
case StateTransitionEnum.IDENTITY_CREDIT_WITHDRAWAL: {
decoded.senderId = stateTransition.getIdentityId().toString()
decoded.amount = parseInt(stateTransition.getAmount())
decoded.nonce = parseInt(stateTransition.getNonce())
decoded.outputScript = stateTransition.getOutputScript().toString('hex')
decoded.coreFeePerByte = stateTransition.getCoreFeePerByte()

break
}
default:
throw new Error('Unknown state transition')
}
Expand Down
3 changes: 3 additions & 0 deletions packages/api/test/mocks/identity_withdrawal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"data": "BQDdzsyM1A38HYinE1o/KYNMqHiPhEvKEDSRQFB5BfCZJvwAD0JAAgAZdqkUjcX9a+GUOQA1zKYpOjV7rI48NcWIrAECQR+EIt94K15RuKU65G/pt6koDfTeV18DHljtUn56F8HpqDn8av49H5COVgsphmQCzKOHHA/smVMJVnreK5n3asT2"
}
14 changes: 14 additions & 0 deletions packages/api/test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const identityTopUpMock = require('./mocks/identity_top_up.json')
const data_contract_update = require('./mocks/data_contract_update.json')
const identityUpdateMock = require('./mocks/identity_update.json')
const identityCreditTransfer = require('./mocks/identity_credit_transfer.json')
const identityWithdrawal = require('./mocks/identity_withdrawal.json')
const Dash = require("dash");


Expand Down Expand Up @@ -98,5 +99,18 @@ describe('Utils', () => {
type: 7
});
});

it('should decode IdentityWithdrawal', async () => {
const decoded = await utils.decodeStateTransition(client, identityWithdrawal.data)

assert.deepEqual(decoded, {
senderId: 'FvqzjDyub72Hk51pcmJvd1JUACuor7vA3aJawiVG7Z17',
amount: 1000000,
nonce: 1,
outputScript: '76a9148dc5fd6be194390035cca6293a357bac8e3c35c588ac',
coreFeePerByte: 2,
type: 6
});
});
});
});

0 comments on commit 236810a

Please sign in to comment.