Skip to content

Commit 228a56f

Browse files
committed
Implement atomic txn composer and fix variable shadow issues
1 parent d71093c commit 228a56f

File tree

9 files changed

+685
-20
lines changed

9 files changed

+685
-20
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = {
2424
},
2525
],
2626
'import/prefer-default-export': 'off',
27+
'no-continue': 'off',
2728
'lines-between-class-members': [
2829
'error',
2930
'always',
@@ -33,6 +34,8 @@ module.exports = {
3334
'@typescript-eslint/no-unused-vars': ['error'],
3435
'no-redeclare': 'off',
3536
'@typescript-eslint/no-redeclare': ['error'],
37+
'no-shadow': 'off',
38+
'@typescript-eslint/no-shadow': ['error'],
3639
},
3740
overrides: [
3841
{

src/abi/abi_type.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ interface Segment {
3131
const staticArrayRegexp = /^([a-z\d[\](),]+)\[([1-9][\d]*)]$/;
3232
const ufixedRegexp = /^ufixed([1-9][\d]*)x([1-9][\d]*)$/;
3333

34-
type ABIValue = boolean | number | bigint | string | Uint8Array | ABIValue[];
34+
export type ABIValue =
35+
| boolean
36+
| number
37+
| bigint
38+
| string
39+
| Uint8Array
40+
| ABIValue[];
3541

3642
export abstract class ABIType {
3743
// Converts a ABIType object to a string
@@ -691,28 +697,26 @@ export class ABITupleType extends ABIType {
691697

692698
// Check segment indices are valid
693699
// If the dynamic segment are not consecutive and well-ordered, we return error
694-
// eslint-disable-next-line no-shadow
695-
for (let i = 0; i < dynamicSegments.length; i++) {
696-
const seg = dynamicSegments[i];
700+
for (let j = 0; j < dynamicSegments.length; j++) {
701+
const seg = dynamicSegments[j];
697702
if (seg.left > seg.right) {
698703
throw new Error(
699704
'dynamic segment should display a [l, r] space with l <= r'
700705
);
701706
}
702707
if (
703-
i !== dynamicSegments.length - 1 &&
704-
seg.right !== dynamicSegments[i + 1].left
708+
j !== dynamicSegments.length - 1 &&
709+
seg.right !== dynamicSegments[j + 1].left
705710
) {
706711
throw new Error('dynamic segment should be consecutive');
707712
}
708713
}
709714

710715
// Check dynamic element partitions
711716
let segIndex = 0;
712-
// eslint-disable-next-line no-shadow
713-
for (let i = 0; i < tupleTypes.length; i++) {
714-
if (tupleTypes[i].isDynamic()) {
715-
valuePartition[i] = byteString.slice(
717+
for (let j = 0; j < tupleTypes.length; j++) {
718+
if (tupleTypes[j].isDynamic()) {
719+
valuePartition[j] = byteString.slice(
716720
dynamicSegments[segIndex].left,
717721
dynamicSegments[segIndex].right
718722
);
@@ -722,9 +726,8 @@ export class ABITupleType extends ABIType {
722726

723727
// Decode each tuple element
724728
const returnValues: ABIValue[] = [];
725-
// eslint-disable-next-line no-shadow
726-
for (let i = 0; i < tupleTypes.length; i++) {
727-
const valueTi = tupleTypes[i].decode(valuePartition[i]);
729+
for (let j = 0; j < tupleTypes.length; j++) {
730+
const valueTi = tupleTypes[j].decode(valuePartition[j]);
728731
returnValues.push(valueTi);
729732
}
730733
return returnValues;

src/abi/method.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { genericHash } from '../nacl/naclWrappers';
2+
import { TransactionType } from '../types/transactions/base';
23
import { ABIType, ABITupleType } from './abi_type';
34

4-
const transactionTypes = ['pay', 'keyreg', 'acfg', 'axfer', 'afrz', 'appl'];
5+
export function abiTypeIsTransaction(type: string): boolean {
6+
return Object.keys(TransactionType).includes(type);
7+
}
58

69
function parseMethodSignature(
710
signature: string
@@ -56,7 +59,7 @@ export class ABIMethod {
5659
txnCount(): number {
5760
let count = 1;
5861
for (const arg of this.args) {
59-
if (transactionTypes.includes(arg.type)) {
62+
if (abiTypeIsTransaction(arg.type)) {
6063
count += 1;
6164
}
6265
}
@@ -68,7 +71,7 @@ export class ABIMethod {
6871

6972
// ensure each arg and return type is valid
7073
args.forEach((arg) => {
71-
if (!transactionTypes.includes(arg)) {
74+
if (!abiTypeIsTransaction(arg)) {
7275
ABIType.from(arg);
7376
}
7477
});

0 commit comments

Comments
 (0)