Skip to content

Commit

Permalink
convert accounting tx
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Dec 3, 2019
1 parent b793db3 commit 1d0863d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions app/api/ada/transactions/shelley/accountingTransaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe('Create unsigned TX for account', () => {

const unsignedTxResponse = buildUnsignedAccountTx(
senderKey.to_public(),
'ca1qw8mq0p65pf028qgd32t6szeatfd9epx4jyl5jeuuswtlkyqpdguqeh83d4',
Buffer.from(RustModule.WalletV3.Address.from_string(
'ca1qw8mq0p65pf028qgd32t6szeatfd9epx4jyl5jeuuswtlkyqpdguqeh83d4'
).as_bytes()).toString('hex'),
{
amount: new BigNumber(2000000)
},
Expand Down Expand Up @@ -64,7 +66,9 @@ describe('Create unsigned TX for account', () => {

expect(() => buildUnsignedAccountTx(
senderKey.to_public(),
'ca1qw8mq0p65pf028qgd32t6szeatfd9epx4jyl5jeuuswtlkyqpdguqeh83d4',
Buffer.from(RustModule.WalletV3.Address.from_string(
'ca1qw8mq0p65pf028qgd32t6szeatfd9epx4jyl5jeuuswtlkyqpdguqeh83d4'
).as_bytes()).toString('hex'),
{
amount: new BigNumber(2000000),
},
Expand All @@ -79,7 +83,9 @@ describe('Create unsigned TX for account', () => {

expect(() => buildUnsignedAccountTx(
senderKey.to_public(),
'ca1qw8mq0p65pf028qgd32t6szeatfd9epx4jyl5jeuuswtlkyqpdguqeh83d4',
Buffer.from(RustModule.WalletV3.Address.from_string(
'ca1qw8mq0p65pf028qgd32t6szeatfd9epx4jyl5jeuuswtlkyqpdguqeh83d4'
).as_bytes()).toString('hex'),
{
amount: new BigNumber(2000000),
},
Expand Down
7 changes: 5 additions & 2 deletions app/api/ada/transactions/shelley/accountingTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export function buildUnsignedAccountTx(
typeSpecific: SendType,
accountBalance: BigNumber,
): RustModule.WalletV3.InputOutput {
const wasmReceiver = RustModule.WalletV3.Address.from_bytes(
Buffer.from(receiver, 'hex')
);
if (typeSpecific.amount != null && typeSpecific.amount.gt(accountBalance)) {
throw new NotEnoughMoneyToSendError();
}
Expand Down Expand Up @@ -52,7 +55,7 @@ export function buildUnsignedAccountTx(

if (typeSpecific.amount != null) {
fakeTxBuilder.add_output(
RustModule.WalletV3.Address.from_string(receiver),
wasmReceiver,
// the value we put in here is irrelevant. Just need some value to be able to calculate fee
RustModule.WalletV3.Value.from_str('1')
);
Expand All @@ -79,7 +82,7 @@ export function buildUnsignedAccountTx(
if (typeSpecific.amount != null) {
const value = RustModule.WalletV3.Value.from_str(typeSpecific.amount.toString());
ioBuilder.add_output(
RustModule.WalletV3.Address.from_string(receiver),
wasmReceiver,
value
);
}
Expand Down

0 comments on commit 1d0863d

Please sign in to comment.