algosdk 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -7
- package/dist/browser/algosdk.min.js +1 -1
- package/dist/browser/algosdk.min.js.map +1 -1
- package/dist/cjs/client/v2/algod/algod.js +201 -25
- package/dist/cjs/client/v2/algod/algod.js.map +1 -1
- package/dist/cjs/client/v2/algod/getApplicationBoxByName.js +1 -1
- package/dist/cjs/client/v2/algod/getApplicationBoxes.js +1 -1
- package/dist/cjs/client/v2/algod/getBlockOffsetTimestamp.js +19 -0
- package/dist/cjs/client/v2/algod/getBlockOffsetTimestamp.js.map +1 -0
- package/dist/cjs/client/v2/algod/getSyncRound.js +19 -0
- package/dist/cjs/client/v2/algod/getSyncRound.js.map +1 -0
- package/dist/cjs/client/v2/algod/models/types.js +257 -23
- package/dist/cjs/client/v2/algod/models/types.js.map +1 -1
- package/dist/cjs/client/v2/algod/ready.js +14 -0
- package/dist/cjs/client/v2/algod/ready.js.map +1 -0
- package/dist/cjs/client/v2/algod/setBlockOffsetTimestamp.js +22 -0
- package/dist/cjs/client/v2/algod/setBlockOffsetTimestamp.js.map +1 -0
- package/dist/cjs/client/v2/algod/setSyncRound.js +22 -0
- package/dist/cjs/client/v2/algod/setSyncRound.js.map +1 -0
- package/dist/cjs/client/v2/algod/simulateTransaction.js +4 -19
- package/dist/cjs/client/v2/algod/simulateTransaction.js.map +1 -1
- package/dist/cjs/client/v2/algod/suggestedParams.js +1 -0
- package/dist/cjs/client/v2/algod/suggestedParams.js.map +1 -1
- package/dist/cjs/client/v2/algod/unsetSyncRound.js +18 -0
- package/dist/cjs/client/v2/algod/unsetSyncRound.js.map +1 -0
- package/dist/cjs/composer.js +39 -2
- package/dist/cjs/composer.js.map +1 -1
- package/dist/cjs/main.js.map +1 -1
- package/dist/cjs/makeTxn.js.map +1 -1
- package/dist/cjs/transaction.js +1 -2
- package/dist/cjs/transaction.js.map +1 -1
- package/dist/esm/client/v2/algod/algod.js +178 -25
- package/dist/esm/client/v2/algod/algod.js.map +1 -1
- package/dist/esm/client/v2/algod/getApplicationBoxByName.js +1 -1
- package/dist/esm/client/v2/algod/getApplicationBoxes.js +1 -1
- package/dist/esm/client/v2/algod/getBlockOffsetTimestamp.js +13 -0
- package/dist/esm/client/v2/algod/getBlockOffsetTimestamp.js.map +1 -0
- package/dist/esm/client/v2/algod/getSyncRound.js +13 -0
- package/dist/esm/client/v2/algod/getSyncRound.js.map +1 -0
- package/dist/esm/client/v2/algod/models/types.js +250 -22
- package/dist/esm/client/v2/algod/models/types.js.map +1 -1
- package/dist/esm/client/v2/algod/ready.js +8 -0
- package/dist/esm/client/v2/algod/ready.js.map +1 -0
- package/dist/esm/client/v2/algod/setBlockOffsetTimestamp.js +16 -0
- package/dist/esm/client/v2/algod/setBlockOffsetTimestamp.js.map +1 -0
- package/dist/esm/client/v2/algod/setSyncRound.js +16 -0
- package/dist/esm/client/v2/algod/setSyncRound.js.map +1 -0
- package/dist/esm/client/v2/algod/simulateTransaction.js +4 -19
- package/dist/esm/client/v2/algod/simulateTransaction.js.map +1 -1
- package/dist/esm/client/v2/algod/suggestedParams.js +1 -0
- package/dist/esm/client/v2/algod/suggestedParams.js.map +1 -1
- package/dist/esm/client/v2/algod/unsetSyncRound.js +12 -0
- package/dist/esm/client/v2/algod/unsetSyncRound.js.map +1 -0
- package/dist/esm/composer.js +16 -2
- package/dist/esm/composer.js.map +1 -1
- package/dist/esm/main.js.map +1 -1
- package/dist/esm/makeTxn.js.map +1 -1
- package/dist/esm/transaction.js +1 -2
- package/dist/esm/transaction.js.map +1 -1
- package/dist/types/client/v2/algod/algod.d.ts +145 -24
- package/dist/types/client/v2/algod/getApplicationBoxByName.d.ts +1 -1
- package/dist/types/client/v2/algod/getApplicationBoxes.d.ts +1 -1
- package/dist/types/client/v2/algod/getBlockOffsetTimestamp.d.ts +6 -0
- package/dist/types/client/v2/algod/getSyncRound.d.ts +6 -0
- package/dist/types/client/v2/algod/models/types.d.ts +236 -29
- package/dist/types/client/v2/algod/ready.d.ts +4 -0
- package/dist/types/client/v2/algod/setBlockOffsetTimestamp.d.ts +9 -0
- package/dist/types/client/v2/algod/setSyncRound.d.ts +9 -0
- package/dist/types/client/v2/algod/simulateTransaction.d.ts +3 -3
- package/dist/types/client/v2/algod/suggestedParams.d.ts +3 -3
- package/dist/types/client/v2/algod/unsetSyncRound.d.ts +5 -0
- package/dist/types/composer.d.ts +5 -2
- package/dist/types/main.d.ts +1 -0
- package/dist/types/makeTxn.d.ts +1 -3
- package/dist/types/types/transactions/base.d.ts +6 -0
- package/package.json +2 -2
- package/src/client/v2/algod/algod.ts +184 -25
- package/src/client/v2/algod/getApplicationBoxByName.ts +1 -1
- package/src/client/v2/algod/getApplicationBoxes.ts +1 -1
- package/src/client/v2/algod/getBlockOffsetTimestamp.ts +17 -0
- package/src/client/v2/algod/getSyncRound.ts +17 -0
- package/src/client/v2/algod/models/types.ts +454 -36
- package/src/client/v2/algod/ready.ts +8 -0
- package/src/client/v2/algod/setBlockOffsetTimestamp.ts +20 -0
- package/src/client/v2/algod/setSyncRound.ts +20 -0
- package/src/client/v2/algod/simulateTransaction.ts +6 -22
- package/src/client/v2/algod/suggestedParams.ts +4 -3
- package/src/client/v2/algod/unsetSyncRound.ts +13 -0
- package/src/composer.ts +27 -3
- package/src/main.ts +7 -0
- package/src/makeTxn.ts +2 -4
- package/src/transaction.ts +1 -2
- package/src/types/transactions/base.ts +7 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import JSONRequest from '../jsonrequest';
|
|
2
|
+
import HTTPClient from '../../client';
|
|
3
|
+
import IntDecoding from '../../../types/intDecoding';
|
|
4
|
+
|
|
5
|
+
export default class SetBlockOffsetTimestamp extends JSONRequest {
|
|
6
|
+
constructor(c: HTTPClient, intDecoding: IntDecoding, private offset: number) {
|
|
7
|
+
super(c, intDecoding);
|
|
8
|
+
|
|
9
|
+
this.offset = offset;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
path() {
|
|
13
|
+
return `/v2/devmode/blocks/offset/${this.offset}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async do(headers = {}) {
|
|
17
|
+
const res = await this.c.post(this.path(), headers);
|
|
18
|
+
return res.body;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import JSONRequest from '../jsonrequest';
|
|
2
|
+
import HTTPClient from '../../client';
|
|
3
|
+
import IntDecoding from '../../../types/intDecoding';
|
|
4
|
+
|
|
5
|
+
export default class SetSyncRound extends JSONRequest {
|
|
6
|
+
constructor(c: HTTPClient, intDecoding: IntDecoding, private round: number) {
|
|
7
|
+
super(c, intDecoding);
|
|
8
|
+
|
|
9
|
+
this.round = round;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
path() {
|
|
13
|
+
return `/v2/ledger/sync/${this.round}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async do(headers = {}) {
|
|
17
|
+
const res = await this.c.post(this.path(), headers);
|
|
18
|
+
return res.body;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import * as encoding from '../../../encoding/encoding';
|
|
3
|
-
import { concatArrays } from '../../../utils/utils';
|
|
4
3
|
import HTTPClient from '../../client';
|
|
5
4
|
import JSONRequest from '../jsonrequest';
|
|
6
|
-
import { SimulateResponse } from './models/types';
|
|
5
|
+
import { SimulateRequest, SimulateResponse } from './models/types';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Sets the default header (if not previously set) for simulating a raw
|
|
@@ -14,15 +13,11 @@ export function setSimulateTransactionsHeaders(headers = {}) {
|
|
|
14
13
|
let hdrs = headers;
|
|
15
14
|
if (Object.keys(hdrs).every((key) => key.toLowerCase() !== 'content-type')) {
|
|
16
15
|
hdrs = { ...headers };
|
|
17
|
-
hdrs['Content-Type'] = 'application/
|
|
16
|
+
hdrs['Content-Type'] = 'application/msgpack';
|
|
18
17
|
}
|
|
19
18
|
return hdrs;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
function isByteArray(array: any): array is Uint8Array {
|
|
23
|
-
return array && array.byteLength !== undefined;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
/**
|
|
27
22
|
* Simulates signed txns.
|
|
28
23
|
*/
|
|
@@ -30,23 +25,12 @@ export default class SimulateRawTransactions extends JSONRequest<
|
|
|
30
25
|
SimulateResponse,
|
|
31
26
|
Uint8Array
|
|
32
27
|
> {
|
|
33
|
-
private
|
|
28
|
+
private requestBytes: Uint8Array;
|
|
34
29
|
|
|
35
|
-
constructor(c: HTTPClient,
|
|
30
|
+
constructor(c: HTTPClient, request: SimulateRequest) {
|
|
36
31
|
super(c);
|
|
37
32
|
this.query.format = 'msgpack';
|
|
38
|
-
|
|
39
|
-
let forPosting = stxOrStxs;
|
|
40
|
-
if (Array.isArray(stxOrStxs)) {
|
|
41
|
-
if (!stxOrStxs.every(isByteArray)) {
|
|
42
|
-
throw new TypeError('Array elements must be byte arrays');
|
|
43
|
-
}
|
|
44
|
-
// Flatten into a single Uint8Array
|
|
45
|
-
forPosting = concatArrays(...stxOrStxs);
|
|
46
|
-
} else if (!isByteArray(forPosting)) {
|
|
47
|
-
throw new TypeError('Argument must be byte array');
|
|
48
|
-
}
|
|
49
|
-
this.txnBytesToPost = forPosting;
|
|
33
|
+
this.requestBytes = encoding.rawEncode(request.get_obj_for_encoding(true));
|
|
50
34
|
}
|
|
51
35
|
|
|
52
36
|
// eslint-disable-next-line class-methods-use-this
|
|
@@ -58,7 +42,7 @@ export default class SimulateRawTransactions extends JSONRequest<
|
|
|
58
42
|
const txHeaders = setSimulateTransactionsHeaders(headers);
|
|
59
43
|
const res = await this.c.post(
|
|
60
44
|
this.path(),
|
|
61
|
-
Buffer.from(this.
|
|
45
|
+
Buffer.from(this.requestBytes),
|
|
62
46
|
txHeaders,
|
|
63
47
|
this.query,
|
|
64
48
|
false
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import JSONRequest from '../jsonrequest';
|
|
2
|
-
import {
|
|
2
|
+
import { SuggestedParamsWithMinFee } from '../../../types/transactions/base';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the common needed parameters for a new transaction, in a format the transaction builder expects
|
|
6
6
|
*/
|
|
7
|
-
export default class SuggestedParamsRequest extends JSONRequest<
|
|
7
|
+
export default class SuggestedParamsRequest extends JSONRequest<SuggestedParamsWithMinFee> {
|
|
8
8
|
/* eslint-disable class-methods-use-this */
|
|
9
9
|
path() {
|
|
10
10
|
return '/v2/transactions/params';
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
prepare(body: Record<string, any>):
|
|
13
|
+
prepare(body: Record<string, any>): SuggestedParamsWithMinFee {
|
|
14
14
|
return {
|
|
15
15
|
flatFee: false,
|
|
16
16
|
fee: body.fee,
|
|
@@ -18,6 +18,7 @@ export default class SuggestedParamsRequest extends JSONRequest<SuggestedParams>
|
|
|
18
18
|
lastRound: body['last-round'] + 1000,
|
|
19
19
|
genesisID: body['genesis-id'],
|
|
20
20
|
genesisHash: body['genesis-hash'],
|
|
21
|
+
minFee: body['min-fee'],
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
/* eslint-enable class-methods-use-this */
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import JSONRequest from '../jsonrequest';
|
|
2
|
+
|
|
3
|
+
export default class UnsetSyncRound extends JSONRequest {
|
|
4
|
+
// eslint-disable-next-line class-methods-use-this
|
|
5
|
+
path() {
|
|
6
|
+
return `/v2/ledger/sync`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async do(headers = {}) {
|
|
10
|
+
const res = await this.c.delete(this.path(), headers);
|
|
11
|
+
return res.body;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/composer.ts
CHANGED
|
@@ -12,7 +12,12 @@ import {
|
|
|
12
12
|
ABIValue,
|
|
13
13
|
} from './abi';
|
|
14
14
|
import Algodv2 from './client/v2/algod/algod';
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
SimulateResponse,
|
|
17
|
+
SimulateRequest,
|
|
18
|
+
SimulateRequestTransactionGroup,
|
|
19
|
+
} from './client/v2/algod/models/types';
|
|
20
|
+
import { EncodedSignedTransaction } from './types';
|
|
16
21
|
import { assignGroupID } from './group';
|
|
17
22
|
import { makeApplicationCallTxnFromObject } from './makeTxn';
|
|
18
23
|
import {
|
|
@@ -27,6 +32,7 @@ import {
|
|
|
27
32
|
SuggestedParams,
|
|
28
33
|
} from './types/transactions/base';
|
|
29
34
|
import { waitForConfirmation } from './wait';
|
|
35
|
+
import * as encoding from './encoding/encoding';
|
|
30
36
|
|
|
31
37
|
// First 4 bytes of SHA-512/256 hash of "return"
|
|
32
38
|
const RETURN_PREFIX = Buffer.from([21, 31, 124, 117]);
|
|
@@ -609,13 +615,17 @@ export class AtomicTransactionComposer {
|
|
|
609
615
|
* Simulating the group will not change the composer's status.
|
|
610
616
|
*
|
|
611
617
|
* @param client - An Algodv2 client
|
|
618
|
+
* @param request - SimulateRequest with options in simulation.
|
|
619
|
+
* If provided, the request's transaction group will be overrwritten by the composer's group,
|
|
620
|
+
* only simulation related options will be used.
|
|
612
621
|
*
|
|
613
622
|
* @returns A promise that, upon success, resolves to an object containing an
|
|
614
623
|
* array of results containing one element for each method call transaction
|
|
615
624
|
* in this group (ABIResult[]) and the SimulateResponse object.
|
|
616
625
|
*/
|
|
617
626
|
async simulate(
|
|
618
|
-
client: Algodv2
|
|
627
|
+
client: Algodv2,
|
|
628
|
+
request?: SimulateRequest
|
|
619
629
|
): Promise<{
|
|
620
630
|
methodResults: ABIResult[];
|
|
621
631
|
simulateResponse: SimulateResponse;
|
|
@@ -627,8 +637,22 @@ export class AtomicTransactionComposer {
|
|
|
627
637
|
}
|
|
628
638
|
|
|
629
639
|
const stxns = await this.gatherSignatures();
|
|
640
|
+
const txnObjects: EncodedSignedTransaction[] = stxns.map(
|
|
641
|
+
(stxn) => encoding.decode(stxn) as EncodedSignedTransaction
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
const currentRequest: SimulateRequest =
|
|
645
|
+
request == null ? new SimulateRequest({ txnGroups: [] }) : request;
|
|
646
|
+
|
|
647
|
+
currentRequest.txnGroups = [
|
|
648
|
+
new SimulateRequestTransactionGroup({
|
|
649
|
+
txns: txnObjects,
|
|
650
|
+
}),
|
|
651
|
+
];
|
|
630
652
|
|
|
631
|
-
const simulateResponse = await client
|
|
653
|
+
const simulateResponse = await client
|
|
654
|
+
.simulateTransactions(currentRequest)
|
|
655
|
+
.do();
|
|
632
656
|
|
|
633
657
|
// Parse method response
|
|
634
658
|
const methodResults: ABIResult[] = [];
|
package/src/main.ts
CHANGED
|
@@ -127,6 +127,13 @@ export {
|
|
|
127
127
|
BaseHTTPClientResponse,
|
|
128
128
|
BaseHTTPClientError,
|
|
129
129
|
} from './client/baseHTTPClient';
|
|
130
|
+
export {
|
|
131
|
+
AlgodTokenHeader,
|
|
132
|
+
IndexerTokenHeader,
|
|
133
|
+
KMDTokenHeader,
|
|
134
|
+
CustomTokenHeader,
|
|
135
|
+
TokenHeader,
|
|
136
|
+
} from './client/urlTokenBaseHTTPClient';
|
|
130
137
|
export { waitForConfirmation } from './wait';
|
|
131
138
|
export {
|
|
132
139
|
isValidAddress,
|
package/src/makeTxn.ts
CHANGED
|
@@ -200,10 +200,8 @@ export function makeKeyRegistrationTxnWithSuggestedParamsFromObject(
|
|
|
200
200
|
'reKeyTo',
|
|
201
201
|
'rekeyTo'
|
|
202
202
|
>,
|
|
203
|
-
'from' | 'note' | 'suggestedParams' | 'rekeyTo'
|
|
204
|
-
>
|
|
205
|
-
nonParticipation: true;
|
|
206
|
-
}
|
|
203
|
+
'from' | 'note' | 'suggestedParams' | 'rekeyTo' | 'nonParticipation'
|
|
204
|
+
>
|
|
207
205
|
>
|
|
208
206
|
): txnBuilder.Transaction;
|
|
209
207
|
export function makeKeyRegistrationTxnWithSuggestedParamsFromObject(o: any) {
|
package/src/transaction.ts
CHANGED
|
@@ -1290,10 +1290,9 @@ export function encodeUnsignedSimulateTransaction(
|
|
|
1290
1290
|
transactionObject: Transaction
|
|
1291
1291
|
) {
|
|
1292
1292
|
const objToEncode: EncodedSignedTransaction = {
|
|
1293
|
-
sig: null,
|
|
1294
1293
|
txn: transactionObject.get_obj_for_encoding(),
|
|
1295
1294
|
};
|
|
1296
|
-
return encoding.
|
|
1295
|
+
return encoding.encode(objToEncode);
|
|
1297
1296
|
}
|
|
1298
1297
|
|
|
1299
1298
|
/**
|
|
@@ -130,6 +130,13 @@ export interface SuggestedParams {
|
|
|
130
130
|
genesisHash: string;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
export type SuggestedParamsWithMinFee = SuggestedParams & {
|
|
134
|
+
/**
|
|
135
|
+
* Minimum fee (not per byte) required for the transaction to be confirmed
|
|
136
|
+
*/
|
|
137
|
+
minFee: number;
|
|
138
|
+
};
|
|
139
|
+
|
|
133
140
|
/**
|
|
134
141
|
* A grouping of the app ID and name of the box in an Uint8Array
|
|
135
142
|
*/
|