Skip to content

Commit ca29709

Browse files
committed
rebase changes
1 parent e09319f commit ca29709

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

__tests__/template/transaction/executor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,6 @@ const ShuffleExecutorTest = async executor => {
593593
};
594594

595595
const ChargeableInputsTest = async executor => {
596-
const ctx = new TxTemplateContext(getDefaultLogger(), DEBUG);
597596
const interpreter = {
598597
getTokenDetails: jest.fn().mockResolvedValue(mockFeeTokenDetails),
599598
getTx: jest.fn().mockReturnValue(
@@ -613,6 +612,7 @@ const ChargeableInputsTest = async executor => {
613612
})
614613
),
615614
};
615+
const ctx = new TxTemplateContext(interpreter, getDefaultLogger(), DEBUG);
616616

617617
// Add two non-authority inputs from the same transaction
618618
const ins1 = RawInputInstruction.parse({ type: 'input/raw', index: 0, txId });
@@ -633,11 +633,11 @@ const ChargeableInputsTest = async executor => {
633633
};
634634

635635
const ChargeableOutputsTest = async executor => {
636-
const ctx = new TxTemplateContext(getDefaultLogger(), DEBUG);
637636
const interpreter = {
638637
getNetwork: jest.fn().mockReturnValue(new Network('testnet')),
639638
getTokenDetails: jest.fn().mockResolvedValue(mockFeeTokenDetails),
640639
};
640+
const ctx = new TxTemplateContext(interpreter, getDefaultLogger(), DEBUG);
641641

642642
// Add three token outputs
643643
const ins1 = TokenOutputInstruction.parse({

src/template/transaction/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export class TokenBalance {
5959
}
6060

6161
calculateFee(): bigint {
62-
let fee = 0;
62+
let fee = 0n;
6363
if (this.chargeableOutputs > 0) {
64-
fee += this.chargeableOutputs * FEE_PER_OUTPUT;
64+
fee += BigInt(this.chargeableOutputs) * FEE_PER_OUTPUT;
6565
} else if (this.chargeableInputs > 0) {
6666
fee += FEE_PER_OUTPUT;
6767
}

src/template/transaction/executor.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ import {
3131
TokenOutputInstruction,
3232
TxTemplateInstruction,
3333
UtxoSelectInstruction,
34-
FeeInstruction,
3534
getVariable,
3635
} from './instructions';
37-
import { TokenBalance, TxTemplateContext } from './context';
36+
import { TxTemplateContext } from './context';
3837
import { ITxTemplateInterpreter, IGetUtxosOptions } from './types';
3938
import Input from '../../models/input';
4039
import Output from '../../models/output';
@@ -149,7 +148,7 @@ export async function execRawInputInstruction(
149148
// Find the original transaction from the input
150149
const origTx = await interpreter.getTx(txId);
151150
// Add balance to the ctx.balance
152-
await ctx.balance.addBalanceFromUtxo(interpreter, origTx, index);
151+
await ctx.balance.addBalanceFromUtxo(origTx, index);
153152

154153
const input = new Input(txId, index);
155154
ctx.addInputs(position, input);
@@ -285,11 +284,11 @@ export async function execRawOutputInstruction(
285284
tokenData = ctx.addToken(token);
286285
if (authority) {
287286
ctx.log(`Creating authority output`);
288-
await ctx.balance.addOutputAuthority(_interpreter, 1, token, authority);
287+
await ctx.balance.addOutputAuthority(1, token, authority);
289288
} else {
290289
ctx.log(`Creating token output`);
291290
if (amount) {
292-
await ctx.balance.addOutput(_interpreter, amount, token);
291+
await ctx.balance.addOutput(amount, token);
293292
}
294293
}
295294
}
@@ -345,7 +344,7 @@ export async function execDataOutputInstruction(
345344
ctx.log(`Using token(${token})`);
346345
// Add token to tokens array
347346
tokenData = ctx.addToken(token);
348-
await ctx.balance.addOutput(_interpreter, 1n, token);
347+
await ctx.balance.addOutput(1n, token);
349348
}
350349

351350
const dataScript = new ScriptData(data);
@@ -391,7 +390,7 @@ export async function execTokenOutputInstruction(
391390
ctx.log(`Using token(${token})`);
392391
// Add token to tokens array
393392
tokenData = ctx.addToken(token);
394-
await ctx.balance.addOutput(interpreter, amount, token);
393+
await ctx.balance.addOutput(amount, token);
395394
}
396395

397396
const script = createOutputScriptFromAddress(address, interpreter.getNetwork());
@@ -450,7 +449,7 @@ export async function execAuthorityOutputInstruction(
450449
// Add token to tokens array
451450
tokenData = ctx.addToken(token);
452451
// Add balance to the ctx.balance
453-
await ctx.balance.addOutputAuthority(interpreter, count, token, authority);
452+
await ctx.balance.addOutputAuthority(count, token, authority);
454453
}
455454

456455
let amount: OutputValueType | undefined = 0n;
@@ -670,7 +669,7 @@ export async function execCompleteTxInstruction(
670669
ctx.log(`Creating ${count} mint outputs / ${tokenUid}`);
671670
// Need to create a token output
672671
// Add balance to the ctx.balance
673-
await ctx.balance.addOutputAuthority(interpreter, count, tokenUid, 'mint');
672+
await ctx.balance.addOutputAuthority(count, tokenUid, 'mint');
674673

675674
// Creates an output with the value of the outstanding balance
676675
const output = new Output(TOKEN_MINT_MASK, changeScript, {
@@ -697,7 +696,7 @@ export async function execCompleteTxInstruction(
697696
// First, update balance
698697
for (const input of inputs) {
699698
const origTx = await interpreter.getTx(input.hash);
700-
await ctx.balance.addBalanceFromUtxo(interpreter, origTx, input.index);
699+
await ctx.balance.addBalanceFromUtxo(origTx, input.index);
701700
}
702701

703702
// Then add inputs to context
@@ -709,7 +708,7 @@ export async function execCompleteTxInstruction(
709708
ctx.log(`Creating ${count} melt outputs / ${tokenUid}`);
710709
// Need to create a token output
711710
// Add balance to the ctx.balance
712-
await ctx.balance.addOutputAuthority(interpreter, count, tokenUid, 'melt');
711+
await ctx.balance.addOutputAuthority(count, tokenUid, 'melt');
713712

714713
// Creates an output with the value of the outstanding balance
715714
const output = new Output(TOKEN_MELT_MASK, changeScript, {
@@ -736,7 +735,7 @@ export async function execCompleteTxInstruction(
736735
// First, update balance
737736
for (const input of inputs) {
738737
const origTx = await interpreter.getTx(input.hash);
739-
await ctx.balance.addBalanceFromUtxo(interpreter, origTx, input.index);
738+
await ctx.balance.addBalanceFromUtxo(origTx, input.index);
740739
}
741740

742741
// Then add inputs to context

src/template/transaction/interpreter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class WalletTxTemplateInterpreter implements ITxTemplateInterpreter {
207207
context.tokenSymbol,
208208
context.inputs,
209209
context.outputs,
210-
{ signalBits: context.signalBits, headers, tokenInfoVersion: context.tokenVersion }
210+
{ signalBits: context.signalBits, headers, tokenVersion: context.tokenVersion }
211211
);
212212
}
213213
throw new Error('Unsupported Version byte provided');

src/template/transaction/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function selectTokens(
3636
inputs.push(new Input(utxo.txId, utxo.index));
3737
// Update the balance
3838
const origTx = await interpreter.getTx(utxo.txId);
39-
await ctx.balance.addBalanceFromUtxo(interpreter, origTx, utxo.index);
39+
await ctx.balance.addBalanceFromUtxo(origTx, utxo.index);
4040
}
4141

4242
// Then add inputs to context
@@ -50,7 +50,7 @@ export async function selectTokens(
5050
const tokenData = ctx.addToken(token);
5151
const script = createOutputScriptFromAddress(changeAddress, interpreter.getNetwork());
5252
const output = new Output(changeAmount, script, { tokenData });
53-
await ctx.balance.addOutput(interpreter, changeAmount, token);
53+
await ctx.balance.addOutput(changeAmount, token);
5454
ctx.addOutputs(-1, output);
5555
}
5656
}
@@ -76,7 +76,7 @@ export async function selectAuthorities(
7676
inputs.push(new Input(utxo.txId, utxo.index));
7777
// Update the balance
7878
const origTx = await interpreter.getTx(utxo.txId);
79-
await ctx.balance.addBalanceFromUtxo(interpreter, origTx, utxo.index);
79+
await ctx.balance.addBalanceFromUtxo(origTx, utxo.index);
8080
}
8181

8282
// Then add inputs to context

0 commit comments

Comments
 (0)