Skip to content

Commit a0366b9

Browse files
authored
REST API: Allow bigints for client args (#893)
1 parent 7fa10ab commit a0366b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+205
-202
lines changed

examples/app.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ async function main() {
7070
3
7171
);
7272
// Grab app id from confirmed transaction result
73-
const appId = Number(result.applicationIndex);
73+
const appId = result.applicationIndex;
74+
if (!appId) {
75+
throw new Error('App not created');
76+
}
7477
console.log(`Created app with index: ${appId}`);
7578
// example: APP_CREATE
7679

examples/asa.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ async function main() {
3737
await algodClient.sendRawTransaction(signedTxn).do();
3838
const result = await algosdk.waitForConfirmation(algodClient, txn.txID(), 3);
3939

40-
const assetIndex = Number(result.assetIndex);
40+
const { assetIndex } = result;
41+
if (!assetIndex) {
42+
throw new Error('Asset not created');
43+
}
4144
console.log(`Asset ID created: ${assetIndex}`);
4245
// example: ASSET_CREATE
4346

examples/atc.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ async function main() {
4545
createTxn.txID(),
4646
3
4747
);
48-
const appIndex = Number(response.applicationIndex);
48+
const appIndex = response.applicationIndex;
49+
if (!appIndex) {
50+
throw new Error('Application not created');
51+
}
4952

5053
// example: ATC_CREATE
5154
const atc = new algosdk.AtomicTransactionComposer();

examples/block_fetcher/index.ts

+16-31
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,42 @@ const address = 'http://127.0.0.1';
1111
const port = 8080;
1212
const client = new algosdk.Algodv2(token, address, port);
1313

14-
// Recursively remove all null values from object
15-
function removeNulls(obj) {
16-
for (const key in obj) {
17-
if (obj[key] === null) {
18-
// eslint-disable-next-line no-param-reassign
19-
delete obj[key];
20-
} else if (typeof obj[key] === 'object') {
21-
removeNulls(obj[key]);
22-
}
23-
}
24-
}
25-
2614
(async () => {
2715
// Retrieve current status
2816
let status = await client.status().do();
2917

3018
while (true) {
3119
// Get latest round number
32-
let lastRound = Number(status.lastRound);
20+
let { lastRound } = status;
3321
console.log(`Round: ${lastRound}`);
3422

3523
// Fetch block
3624
const round = await client.block(lastRound).do();
3725
const { block } = round;
38-
const { txns } = block;
26+
const txns = block.payset;
3927

4028
// For all transactions in the block reconstruct them
4129
// into Transaction objects and calculate their TxID
42-
for (const t in txns) {
43-
const tx = txns[t];
44-
const { txn } = txns[t];
30+
for (const stxnInBlock of txns) {
31+
const { txn } = stxnInBlock.signedTxn.signedTxn;
4532

4633
// Skip StateProofs
47-
if (txn.type === 'stpf') continue;
48-
49-
// Remove nulls (mainly where an appl txn contains a null app arg)
50-
removeNulls(txn);
34+
if (txn.type === algosdk.TransactionType.stpf) continue;
5135

5236
// Use Genesis Hash and Genesis ID from the block
53-
const { gh } = block;
54-
let { gen } = block;
37+
let gh: Uint8Array | undefined = block.header.genesisHash;
38+
let gen: string | undefined = block.header.genesisID;
5539

56-
// Unset gen if `hgi` isn't set
57-
if (!tx.hgi) gen = null;
40+
// Unset gh if hasGenesisID isn't set
41+
if (!stxnInBlock.hasGenesisID) gh = undefined;
42+
// Unset gen if hasGenesisID isn't set
43+
if (!stxnInBlock.hasGenesisID) gen = undefined;
5844

5945
// Construct Transaction
60-
const transaction = algosdk.Transaction.from_obj_for_encoding({
61-
...txn,
62-
gh,
63-
gen,
64-
});
46+
const encodingData = txn.toEncodingData();
47+
encodingData.set('gh', gh);
48+
encodingData.set('gen', gen);
49+
const transaction = algosdk.Transaction.fromEncodingData(encodingData);
6550
const txid = transaction.txID();
6651

6752
// If set to true, validate the TxID exists against the node
@@ -80,6 +65,6 @@ function removeNulls(obj) {
8065

8166
// Wait for next round
8267
status = await client.statusAfterBlock(lastRound).do();
83-
lastRound = status['last-round'];
68+
lastRound = status.lastRound;
8469
}
8570
})();

examples/utils.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export async function getLocalAccounts(): Promise<SandboxAccount[]> {
130130
export async function deployCalculatorApp(
131131
algodClient: algosdk.Algodv2,
132132
creator: SandboxAccount
133-
): Promise<number> {
133+
): Promise<bigint> {
134134
const approvalProgram = fs.readFileSync(
135135
path.join(__dirname, '/calculator/approval.teal'),
136136
'utf8'
@@ -164,6 +164,9 @@ export async function deployCalculatorApp(
164164
appCreateTxn.txID(),
165165
3
166166
);
167-
const appId = Number(result.applicationIndex);
167+
const appId = result.applicationIndex;
168+
if (!appId) {
169+
throw new Error('Application not created');
170+
}
168171
return appId;
169172
}

src/client/urlTokenBaseHTTPClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class URLTokenBaseHTTPClient implements BaseHTTPClient {
9595
const address = new URL(fixedRelativePath, this.baseURL);
9696
if (query) {
9797
for (const [key, value] of Object.entries(query)) {
98-
address.searchParams.set(key, value);
98+
address.searchParams.set(key, value.toString());
9999
}
100100
}
101101
return address.toString();

src/client/v2/algod/accountApplicationInformation.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import { Address } from '../../../encoding/address.js';
66

77
export default class AccountApplicationInformation extends JSONRequest<AccountApplicationResponse> {
88
private account: string;
9+
private applicationID: bigint;
910

1011
constructor(
1112
c: HTTPClient,
1213
account: string | Address,
13-
private applicationID: number
14+
applicationID: number | bigint
1415
) {
1516
super(c);
1617
this.account = account.toString();
18+
this.applicationID = BigInt(applicationID);
1719
}
1820

1921
path() {

src/client/v2/algod/accountAssetInformation.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import { Address } from '../../../encoding/address.js';
66

77
export default class AccountAssetInformation extends JSONRequest<AccountAssetResponse> {
88
private account: string;
9+
private assetID: bigint;
910

1011
constructor(
1112
c: HTTPClient,
1213
account: string | Address,
13-
private assetID: number
14+
assetID: number | bigint
1415
) {
1516
super(c);
1617
this.account = account.toString();
18+
this.assetID = BigInt(assetID);
1719
}
1820

1921
path() {

src/client/v2/algod/algod.ts

+20-17
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class AlgodClient extends ServiceClient {
9696
*
9797
* #### Example
9898
* ```typescript
99-
* const health = await algodClient.healthCheck().do();
99+
* await algodClient.healthCheck().do();
100100
* ```
101101
*
102102
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-health)
@@ -126,7 +126,7 @@ export class AlgodClient extends ServiceClient {
126126
*
127127
* #### Example
128128
* ```typescript
129-
* const { txId } = await algodClient.sendRawTransaction(signedTxns).do();
129+
* const { txid } = await algodClient.sendRawTransaction(signedTxns).do();
130130
* const result = await waitForConfirmation(algodClient, txid, 3);
131131
* ```
132132
*
@@ -173,7 +173,7 @@ export class AlgodClient extends ServiceClient {
173173
* @param index - The asset ID to look up.
174174
* @category GET
175175
*/
176-
accountAssetInformation(account: string | Address, index: number) {
176+
accountAssetInformation(account: string | Address, index: number | bigint) {
177177
return new AccountAssetInformation(this.c, account, index);
178178
}
179179

@@ -192,7 +192,10 @@ export class AlgodClient extends ServiceClient {
192192
* @param index - The application ID to look up.
193193
* @category GET
194194
*/
195-
accountApplicationInformation(account: string | Address, index: number) {
195+
accountApplicationInformation(
196+
account: string | Address,
197+
index: number | bigint
198+
) {
196199
return new AccountApplicationInformation(this.c, account, index);
197200
}
198201

@@ -209,7 +212,7 @@ export class AlgodClient extends ServiceClient {
209212
* @param roundNumber - The round number of the block to get.
210213
* @category GET
211214
*/
212-
block(roundNumber: number) {
215+
block(roundNumber: number | bigint) {
213216
return new Block(this.c, roundNumber);
214217
}
215218

@@ -226,7 +229,7 @@ export class AlgodClient extends ServiceClient {
226229
* @param roundNumber - The round number of the block to get.
227230
* @category GET
228231
*/
229-
getBlockHash(roundNumber: number) {
232+
getBlockHash(roundNumber: number | bigint) {
230233
return new GetBlockHash(this.c, roundNumber);
231234
}
232235

@@ -243,7 +246,7 @@ export class AlgodClient extends ServiceClient {
243246
* @param roundNumber - The round number of the block to get.
244247
* @category GET
245248
*/
246-
getBlockTxids(roundNumber: number) {
249+
getBlockTxids(roundNumber: number | bigint) {
247250
return new GetBlockTxids(this.c, roundNumber);
248251
}
249252

@@ -355,7 +358,7 @@ export class AlgodClient extends ServiceClient {
355358
* @param round - The number of the round to wait for.
356359
* @category GET
357360
*/
358-
statusAfterBlock(round: number) {
361+
statusAfterBlock(round: number | bigint) {
359362
return new StatusAfterBlock(this.c, round);
360363
}
361364

@@ -504,7 +507,7 @@ export class AlgodClient extends ServiceClient {
504507
* @param index - The application ID to look up.
505508
* @category GET
506509
*/
507-
getApplicationBoxByName(index: number, boxName: Uint8Array) {
510+
getApplicationBoxByName(index: number | bigint, boxName: Uint8Array) {
508511
return new GetApplicationBoxByName(this.c, index, boxName);
509512
}
510513

@@ -522,7 +525,7 @@ export class AlgodClient extends ServiceClient {
522525
* @param index - The application ID to look up.
523526
* @category GET
524527
*/
525-
getApplicationBoxes(index: number) {
528+
getApplicationBoxes(index: number | bigint) {
526529
return new GetApplicationBoxes(this.c, index);
527530
}
528531

@@ -556,7 +559,7 @@ export class AlgodClient extends ServiceClient {
556559
* @param txID - The transaction ID for which to generate a proof.
557560
* @category GET
558561
*/
559-
getTransactionProof(round: number, txID: string) {
562+
getTransactionProof(round: number | bigint, txID: string) {
560563
return new GetTransactionProof(this.c, round, txID);
561564
}
562565

@@ -572,7 +575,7 @@ export class AlgodClient extends ServiceClient {
572575
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/v2#get-v2blocksroundlightheaderproof)
573576
* @param round
574577
*/
575-
getLightBlockHeaderProof(round: number) {
578+
getLightBlockHeaderProof(round: number | bigint) {
576579
return new LightBlockHeaderProof(this.c, round);
577580
}
578581

@@ -588,7 +591,7 @@ export class AlgodClient extends ServiceClient {
588591
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/v2#get-v2stateproofsround)
589592
* @param round
590593
*/
591-
getStateProof(round: number) {
594+
getStateProof(round: number | bigint) {
592595
return new StateProof(this.c, round);
593596
}
594597

@@ -678,7 +681,7 @@ export class AlgodClient extends ServiceClient {
678681
* @param offset
679682
* @category POST
680683
*/
681-
setBlockOffsetTimestamp(offset: number) {
684+
setBlockOffsetTimestamp(offset: number | bigint) {
682685
return new SetBlockOffsetTimestamp(this.c, offset);
683686
}
684687

@@ -710,7 +713,7 @@ export class AlgodClient extends ServiceClient {
710713
* @param round
711714
* @category POST
712715
*/
713-
setSyncRound(round: number) {
716+
setSyncRound(round: number | bigint) {
714717
return new SetSyncRound(this.c, round);
715718
}
716719

@@ -789,7 +792,7 @@ export class AlgodClient extends ServiceClient {
789792
* @param round the round number to be searched for
790793
* @category GET
791794
*/
792-
getLedgerStateDelta(round: number) {
795+
getLedgerStateDelta(round: number | bigint) {
793796
return new GetLedgerStateDelta(this.c, round);
794797
}
795798

@@ -806,7 +809,7 @@ export class AlgodClient extends ServiceClient {
806809
* @param round the round number to be searched for
807810
* @category GET
808811
*/
809-
getTransactionGroupLedgerStateDeltasForRound(round: number) {
812+
getTransactionGroupLedgerStateDeltasForRound(round: number | bigint) {
810813
return new GetTransactionGroupLedgerStateDeltasForRound(this.c, round);
811814
}
812815
}

src/client/v2/algod/block.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { BlockResponse } from './models/types.js';
77
* block gets the block info for the given round. this call may block
88
*/
99
export default class Block extends JSONRequest<BlockResponse> {
10-
private round: number;
10+
private round: bigint;
1111

12-
constructor(c: HTTPClient, roundNumber: number) {
12+
constructor(c: HTTPClient, roundNumber: number | bigint) {
1313
super(c);
14-
this.round = roundNumber;
14+
this.round = BigInt(roundNumber);
1515
this.query = { format: 'msgpack' };
1616
}
1717

src/client/v2/algod/getApplicationBoxByName.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ import { Box } from './models/types.js';
2020
* @category GET
2121
*/
2222
export default class GetApplicationBoxByName extends JSONRequest<Box> {
23-
constructor(
24-
c: HTTPClient,
25-
private index: number,
26-
name: Uint8Array
27-
) {
23+
private index: bigint;
24+
25+
constructor(c: HTTPClient, index: number | bigint, name: Uint8Array) {
2826
super(c);
27+
this.index = BigInt(index);
2928
// Encode name in base64 format and append the encoding prefix.
3029
const encodedName = bytesToBase64(name);
3130
this.query.name = encodeURI(`b64:${encodedName}`);

src/client/v2/algod/getApplicationBoxes.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import { BoxesResponse } from './models/types.js';
1818
* @category GET
1919
*/
2020
export default class GetApplicationBoxes extends JSONRequest<BoxesResponse> {
21-
constructor(
22-
c: HTTPClient,
23-
private index: number
24-
) {
21+
private index: bigint;
22+
23+
constructor(c: HTTPClient, index: number | bigint) {
2524
super(c);
25+
this.index = BigInt(index);
2626
this.query.max = 0;
2727
}
2828

0 commit comments

Comments
 (0)