Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.0: Remove API response int decoding option, support BigInt everywhere #816

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ export default class HTTPClient {
jsonOptions: utils.JSONOptions = {}
) {
try {
if (Object.keys(jsonOptions).length === 0) {
return text && JSON.parse(text);
}
return text && utils.parseJSON(text, jsonOptions);
} catch (err_) {
const err: ErrorWithAdditionalInfo = err_;
Expand Down Expand Up @@ -150,7 +147,7 @@ export default class HTTPClient {
return new Uint8Array(0); // empty Uint8Array
}
if (requestHeaders['content-type'] === 'application/json') {
return new TextEncoder().encode(JSON.stringify(data));
return new TextEncoder().encode(utils.stringifyJSON(data));
}
if (typeof data === 'string') {
return new TextEncoder().encode(data);
Expand Down
4 changes: 1 addition & 3 deletions src/client/v2/algod/accountApplicationInformation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';

export default class AccountApplicationInformation extends JSONRequest {
constructor(
c: HTTPClient,
intDecoding: IntDecoding,
private account: string,
private applicationID: number
) {
super(c, intDecoding);
super(c);
this.account = account;
this.applicationID = applicationID;
}
Expand Down
10 changes: 2 additions & 8 deletions src/client/v2/algod/accountAssetInformation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';

export default class AccountAssetInformation extends JSONRequest {
constructor(
c: HTTPClient,
intDecoding: IntDecoding,
private account: string,
private assetID: number
) {
super(c, intDecoding);
constructor(c: HTTPClient, private account: string, private assetID: number) {
super(c);
this.account = account;
this.assetID = assetID;
}
Expand Down
9 changes: 2 additions & 7 deletions src/client/v2/algod/accountInformation.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';

export default class AccountInformation extends JSONRequest {
constructor(
c: HTTPClient,
intDecoding: IntDecoding,
private account: string
) {
super(c, intDecoding);
constructor(c: HTTPClient, private account: string) {
super(c);
this.account = account;
}

Expand Down
71 changes: 24 additions & 47 deletions src/client/v2/algod/algod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
accountInformation(account: string) {
return new AccountInformation(this.c, this.intDecoding, account);
return new AccountInformation(this.c, account);
}

/**
Expand All @@ -172,12 +172,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
accountAssetInformation(account: string, index: number) {
return new AccountAssetInformation(
this.c,
this.intDecoding,
account,
index
);
return new AccountAssetInformation(this.c, account, index);
}

/**
Expand All @@ -196,12 +191,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
accountApplicationInformation(account: string, index: number) {
return new AccountApplicationInformation(
this.c,
this.intDecoding,
account,
index
);
return new AccountApplicationInformation(this.c, account, index);
}

/**
Expand Down Expand Up @@ -235,7 +225,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getBlockHash(roundNumber: number) {
return new GetBlockHash(this.c, this.intDecoding, roundNumber);
return new GetBlockHash(this.c, roundNumber);
}

/**
Expand Down Expand Up @@ -330,7 +320,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
status() {
return new Status(this.c, this.intDecoding);
return new Status(this.c);
}

/**
Expand All @@ -347,7 +337,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
statusAfterBlock(round: number) {
return new StatusAfterBlock(this.c, this.intDecoding, round);
return new StatusAfterBlock(this.c, round);
}

/**
Expand Down Expand Up @@ -388,7 +378,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
supply() {
return new Supply(this.c, this.intDecoding);
return new Supply(this.c);
}

/**
Expand Down Expand Up @@ -459,7 +449,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getAssetByID(index: number) {
return new GetAssetByID(this.c, this.intDecoding, index);
return new GetAssetByID(this.c, index);
}

/**
Expand All @@ -477,7 +467,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getApplicationByID(index: number) {
return new GetApplicationByID(this.c, this.intDecoding, index);
return new GetApplicationByID(this.c, index);
}

/**
Expand All @@ -496,12 +486,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getApplicationBoxByName(index: number, boxName: Uint8Array) {
return new GetApplicationBoxByName(
this.c,
this.intDecoding,
index,
boxName
);
return new GetApplicationBoxByName(this.c, index, boxName);
}

/**
Expand All @@ -519,7 +504,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getApplicationBoxes(index: number) {
return new GetApplicationBoxes(this.c, this.intDecoding, index);
return new GetApplicationBoxes(this.c, index);
}

/**
Expand All @@ -534,7 +519,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
genesis() {
return new Genesis(this.c, this.intDecoding);
return new Genesis(this.c);
}

/**
Expand All @@ -553,7 +538,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getTransactionProof(round: number, txID: string) {
return new GetTransactionProof(this.c, this.intDecoding, round, txID);
return new GetTransactionProof(this.c, round, txID);
}

/**
Expand All @@ -569,7 +554,7 @@ export default class AlgodClient extends ServiceClient {
* @param round
*/
getLightBlockHeaderProof(round: number) {
return new LightBlockHeaderProof(this.c, this.intDecoding, round);
return new LightBlockHeaderProof(this.c, round);
}

/**
Expand All @@ -585,7 +570,7 @@ export default class AlgodClient extends ServiceClient {
* @param round
*/
getStateProof(round: number) {
return new StateProof(this.c, this.intDecoding, round);
return new StateProof(this.c, round);
}

/**
Expand Down Expand Up @@ -675,7 +660,7 @@ export default class AlgodClient extends ServiceClient {
* @category POST
*/
setBlockOffsetTimestamp(offset: number) {
return new SetBlockOffsetTimestamp(this.c, this.intDecoding, offset);
return new SetBlockOffsetTimestamp(this.c, offset);
}

/**
Expand All @@ -690,7 +675,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getBlockOffsetTimestamp() {
return new GetBlockOffsetTimestamp(this.c, this.intDecoding);
return new GetBlockOffsetTimestamp(this.c);
}

/**
Expand All @@ -707,7 +692,7 @@ export default class AlgodClient extends ServiceClient {
* @category POST
*/
setSyncRound(round: number) {
return new SetSyncRound(this.c, this.intDecoding, round);
return new SetSyncRound(this.c, round);
}

/**
Expand All @@ -722,7 +707,7 @@ export default class AlgodClient extends ServiceClient {
* @category DELETE
*/
unsetSyncRound() {
return new UnsetSyncRound(this.c, this.intDecoding);
return new UnsetSyncRound(this.c);
}

/**
Expand All @@ -737,7 +722,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getSyncRound() {
return new GetSyncRound(this.c, this.intDecoding);
return new GetSyncRound(this.c);
}

/**
Expand All @@ -752,7 +737,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
ready() {
return new Ready(this.c, this.intDecoding);
return new Ready(this.c);
}

/**
Expand All @@ -769,11 +754,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getLedgerStateDeltaForTransactionGroup(id: string) {
return new GetLedgerStateDeltaForTransactionGroup(
this.c,
this.intDecoding,
id
);
return new GetLedgerStateDeltaForTransactionGroup(this.c, id);
}

/**
Expand All @@ -790,7 +771,7 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getLedgerStateDelta(round: bigint) {
return new GetLedgerStateDelta(this.c, this.intDecoding, round);
return new GetLedgerStateDelta(this.c, round);
}

/**
Expand All @@ -807,10 +788,6 @@ export default class AlgodClient extends ServiceClient {
* @category GET
*/
getTransactionGroupLedgerStateDeltasForRound(round: bigint) {
return new GetTransactionGroupLedgerStateDeltasForRound(
this.c,
this.intDecoding,
round
);
return new GetTransactionGroupLedgerStateDeltasForRound(this.c, round);
}
}
2 changes: 1 addition & 1 deletion src/client/v2/algod/dryrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class Dryrun extends JSONRequest {

constructor(c: HTTPClient, dr: modelsv2.DryrunRequest) {
super(c);
this.blob = encoding.encode(dr.get_obj_for_encoding(true));
this.blob = encoding.encode(dr.get_obj_for_encoding(true, true));
}

// eslint-disable-next-line class-methods-use-this
Expand Down
10 changes: 2 additions & 8 deletions src/client/v2/algod/getApplicationBoxByName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { bytesToBase64 } from '../../../encoding/binarydata';
import IntDecoding from '../../../types/intDecoding';
import HTTPClient from '../../client';
import JSONRequest from '../jsonrequest';
import { Box } from './models/types';
Expand All @@ -23,13 +22,8 @@ export default class GetApplicationBoxByName extends JSONRequest<
Box,
Record<string, any>
> {
constructor(
c: HTTPClient,
intDecoding: IntDecoding,
private index: number,
name: Uint8Array
) {
super(c, intDecoding);
constructor(c: HTTPClient, private index: number, name: Uint8Array) {
super(c);
this.index = index;
// Encode name in base64 format and append the encoding prefix.
const encodedName = bytesToBase64(name);
Expand Down
5 changes: 2 additions & 3 deletions src/client/v2/algod/getApplicationBoxes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';
import { BoxesResponse } from './models/types';

/**
Expand All @@ -21,8 +20,8 @@ export default class GetApplicationBoxes extends JSONRequest<
BoxesResponse,
Record<string, any>
> {
constructor(c: HTTPClient, intDecoding: IntDecoding, private index: number) {
super(c, intDecoding);
constructor(c: HTTPClient, private index: number) {
super(c);
this.index = index;
this.query.max = 0;
}
Expand Down
5 changes: 2 additions & 3 deletions src/client/v2/algod/getApplicationByID.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';

export default class GetApplicationByID extends JSONRequest {
constructor(c: HTTPClient, intDecoding: IntDecoding, private index: number) {
super(c, intDecoding);
constructor(c: HTTPClient, private index: number) {
super(c);
this.index = index;
}

Expand Down
5 changes: 2 additions & 3 deletions src/client/v2/algod/getAssetByID.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';

export default class GetAssetByID extends JSONRequest {
constructor(c: HTTPClient, intDecoding: IntDecoding, private index: number) {
super(c, intDecoding);
constructor(c: HTTPClient, private index: number) {
super(c);
this.index = index;
}

Expand Down
5 changes: 2 additions & 3 deletions src/client/v2/algod/getBlockHash.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';

export default class GetBlockHash extends JSONRequest {
round: number;

constructor(c: HTTPClient, intDecoding: IntDecoding, roundNumber: number) {
super(c, intDecoding);
constructor(c: HTTPClient, roundNumber: number) {
super(c);
if (!Number.isInteger(roundNumber))
throw Error('roundNumber should be an integer');
this.round = roundNumber;
Expand Down
Loading