Skip to content
Permalink
Browse files

convert accounting tx

  • Loading branch information
SebastienGllmt committed Dec 3, 2019
1 parent b793db3 commit 1d0863dc9a95de64998168ea7f3675f3b987269f
@@ -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)
},
@@ -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),
},
@@ -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),
},
@@ -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();
}
@@ -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')
);
@@ -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
);
}

0 comments on commit 1d0863d

Please sign in to comment.
You can’t perform that action at this time.