algosdk 2.1.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 +215 -23
- 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 +361 -8
- 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 +73 -0
- package/dist/cjs/client/v2/algod/simulateTransaction.js.map +1 -0
- 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 +106 -18
- package/dist/cjs/composer.js.map +1 -1
- package/dist/cjs/encoding/encoding.js +14 -3
- package/dist/cjs/encoding/encoding.js.map +1 -1
- package/dist/cjs/main.js.map +1 -1
- package/dist/cjs/makeTxn.js.map +1 -1
- package/dist/cjs/signer.js +17 -1
- package/dist/cjs/signer.js.map +1 -1
- package/dist/cjs/transaction.js +16 -1
- package/dist/cjs/transaction.js.map +1 -1
- package/dist/esm/client/v2/algod/algod.js +192 -23
- 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 +351 -7
- 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 +42 -0
- package/dist/esm/client/v2/algod/simulateTransaction.js.map +1 -0
- 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 +84 -19
- package/dist/esm/composer.js.map +1 -1
- package/dist/esm/encoding/encoding.js +12 -2
- package/dist/esm/encoding/encoding.js.map +1 -1
- package/dist/esm/main.js.map +1 -1
- package/dist/esm/makeTxn.js.map +1 -1
- package/dist/esm/signer.js +15 -0
- package/dist/esm/signer.js.map +1 -1
- package/dist/esm/transaction.js +14 -0
- package/dist/esm/transaction.js.map +1 -1
- package/dist/types/client/v2/algod/algod.d.ts +158 -23
- 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 +324 -14
- 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 +19 -0
- 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 +31 -1
- package/dist/types/encoding/encoding.d.ts +7 -0
- package/dist/types/main.d.ts +1 -0
- package/dist/types/makeTxn.d.ts +1 -3
- package/dist/types/signer.d.ts +5 -0
- package/dist/types/transaction.d.ts +9 -0
- package/dist/types/types/transactions/base.d.ts +6 -0
- package/dist/types/types/transactions/builder.d.ts +1 -1
- package/dist/types/types/utils.d.ts +1 -1
- package/package.json +2 -2
- package/src/client/v2/algod/algod.ts +199 -23
- 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 +652 -12
- 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 +58 -0
- package/src/client/v2/algod/suggestedParams.ts +4 -3
- package/src/client/v2/algod/unsetSyncRound.ts +13 -0
- package/src/composer.ts +138 -31
- package/src/encoding/encoding.ts +13 -2
- package/src/main.ts +7 -0
- package/src/makeTxn.ts +2 -4
- package/src/signer.ts +18 -1
- package/src/transaction.ts +17 -0
- package/src/types/transactions/base.ts +7 -0
- package/src/types/transactions/builder.ts +4 -4
- package/src/types/utils.ts +1 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import * as encoding from '../../../encoding/encoding';
|
|
3
|
+
import HTTPClient from '../../client';
|
|
4
|
+
import JSONRequest from '../jsonrequest';
|
|
5
|
+
import { SimulateRequest, SimulateResponse } from './models/types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Sets the default header (if not previously set) for simulating a raw
|
|
9
|
+
* transaction.
|
|
10
|
+
* @param headers - A headers object
|
|
11
|
+
*/
|
|
12
|
+
export function setSimulateTransactionsHeaders(headers = {}) {
|
|
13
|
+
let hdrs = headers;
|
|
14
|
+
if (Object.keys(hdrs).every((key) => key.toLowerCase() !== 'content-type')) {
|
|
15
|
+
hdrs = { ...headers };
|
|
16
|
+
hdrs['Content-Type'] = 'application/msgpack';
|
|
17
|
+
}
|
|
18
|
+
return hdrs;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Simulates signed txns.
|
|
23
|
+
*/
|
|
24
|
+
export default class SimulateRawTransactions extends JSONRequest<
|
|
25
|
+
SimulateResponse,
|
|
26
|
+
Uint8Array
|
|
27
|
+
> {
|
|
28
|
+
private requestBytes: Uint8Array;
|
|
29
|
+
|
|
30
|
+
constructor(c: HTTPClient, request: SimulateRequest) {
|
|
31
|
+
super(c);
|
|
32
|
+
this.query.format = 'msgpack';
|
|
33
|
+
this.requestBytes = encoding.rawEncode(request.get_obj_for_encoding(true));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line class-methods-use-this
|
|
37
|
+
path() {
|
|
38
|
+
return '/v2/transactions/simulate';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async do(headers = {}) {
|
|
42
|
+
const txHeaders = setSimulateTransactionsHeaders(headers);
|
|
43
|
+
const res = await this.c.post(
|
|
44
|
+
this.path(),
|
|
45
|
+
Buffer.from(this.requestBytes),
|
|
46
|
+
txHeaders,
|
|
47
|
+
this.query,
|
|
48
|
+
false
|
|
49
|
+
);
|
|
50
|
+
return this.prepare(res.body);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// eslint-disable-next-line class-methods-use-this
|
|
54
|
+
prepare(body: Uint8Array): SimulateResponse {
|
|
55
|
+
const decoded = encoding.decode(body);
|
|
56
|
+
return SimulateResponse.from_obj_for_encoding(decoded);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -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
|
@@ -1,31 +1,38 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import {
|
|
3
|
-
ABIType,
|
|
4
|
-
ABITupleType,
|
|
5
|
-
ABIUintType,
|
|
6
3
|
ABIAddressType,
|
|
7
|
-
|
|
4
|
+
abiCheckTransactionType,
|
|
8
5
|
ABIMethod,
|
|
9
6
|
ABIReferenceType,
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
ABITupleType,
|
|
8
|
+
ABIType,
|
|
12
9
|
abiTypeIsReference,
|
|
10
|
+
abiTypeIsTransaction,
|
|
11
|
+
ABIUintType,
|
|
12
|
+
ABIValue,
|
|
13
13
|
} from './abi';
|
|
14
|
-
import { Transaction, decodeSignedTransaction } from './transaction';
|
|
15
|
-
import { makeApplicationCallTxnFromObject } from './makeTxn';
|
|
16
|
-
import { assignGroupID } from './group';
|
|
17
|
-
import { waitForConfirmation } from './wait';
|
|
18
14
|
import Algodv2 from './client/v2/algod/algod';
|
|
19
15
|
import {
|
|
16
|
+
SimulateResponse,
|
|
17
|
+
SimulateRequest,
|
|
18
|
+
SimulateRequestTransactionGroup,
|
|
19
|
+
} from './client/v2/algod/models/types';
|
|
20
|
+
import { EncodedSignedTransaction } from './types';
|
|
21
|
+
import { assignGroupID } from './group';
|
|
22
|
+
import { makeApplicationCallTxnFromObject } from './makeTxn';
|
|
23
|
+
import {
|
|
24
|
+
isTransactionWithSigner,
|
|
20
25
|
TransactionSigner,
|
|
21
26
|
TransactionWithSigner,
|
|
22
|
-
isTransactionWithSigner,
|
|
23
27
|
} from './signer';
|
|
28
|
+
import { decodeSignedTransaction, Transaction } from './transaction';
|
|
24
29
|
import {
|
|
25
30
|
BoxReference,
|
|
26
31
|
OnApplicationComplete,
|
|
27
32
|
SuggestedParams,
|
|
28
33
|
} from './types/transactions/base';
|
|
34
|
+
import { waitForConfirmation } from './wait';
|
|
35
|
+
import * as encoding from './encoding/encoding';
|
|
29
36
|
|
|
30
37
|
// First 4 bytes of SHA-512/256 hash of "return"
|
|
31
38
|
const RETURN_PREFIX = Buffer.from([21, 31, 124, 117]);
|
|
@@ -600,6 +607,78 @@ export class AtomicTransactionComposer {
|
|
|
600
607
|
return this.txIDs;
|
|
601
608
|
}
|
|
602
609
|
|
|
610
|
+
/**
|
|
611
|
+
* Simulates the transaction group in the network.
|
|
612
|
+
*
|
|
613
|
+
* The composer will try to sign any transactions in the group, then simulate
|
|
614
|
+
* the results.
|
|
615
|
+
* Simulating the group will not change the composer's status.
|
|
616
|
+
*
|
|
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.
|
|
621
|
+
*
|
|
622
|
+
* @returns A promise that, upon success, resolves to an object containing an
|
|
623
|
+
* array of results containing one element for each method call transaction
|
|
624
|
+
* in this group (ABIResult[]) and the SimulateResponse object.
|
|
625
|
+
*/
|
|
626
|
+
async simulate(
|
|
627
|
+
client: Algodv2,
|
|
628
|
+
request?: SimulateRequest
|
|
629
|
+
): Promise<{
|
|
630
|
+
methodResults: ABIResult[];
|
|
631
|
+
simulateResponse: SimulateResponse;
|
|
632
|
+
}> {
|
|
633
|
+
if (this.status > AtomicTransactionComposerStatus.SUBMITTED) {
|
|
634
|
+
throw new Error(
|
|
635
|
+
'Simulated Transaction group has already been submitted to the network'
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
|
|
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
|
+
];
|
|
652
|
+
|
|
653
|
+
const simulateResponse = await client
|
|
654
|
+
.simulateTransactions(currentRequest)
|
|
655
|
+
.do();
|
|
656
|
+
|
|
657
|
+
// Parse method response
|
|
658
|
+
const methodResults: ABIResult[] = [];
|
|
659
|
+
for (const [txnIndex, method] of this.methodCalls) {
|
|
660
|
+
const txID = this.txIDs[txnIndex];
|
|
661
|
+
const pendingInfo =
|
|
662
|
+
simulateResponse.txnGroups[0].txnResults[txnIndex].txnResult;
|
|
663
|
+
|
|
664
|
+
const methodResult: ABIResult = {
|
|
665
|
+
txID,
|
|
666
|
+
rawReturnValue: new Uint8Array(),
|
|
667
|
+
method,
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
methodResults.push(
|
|
671
|
+
AtomicTransactionComposer.parseMethodResponse(
|
|
672
|
+
method,
|
|
673
|
+
methodResult,
|
|
674
|
+
pendingInfo.get_obj_for_encoding()
|
|
675
|
+
)
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
return { methodResults, simulateResponse };
|
|
680
|
+
}
|
|
681
|
+
|
|
603
682
|
/**
|
|
604
683
|
* Send the transaction group to the network and wait until it's committed to a block. An error
|
|
605
684
|
* will be thrown if submission or execution fails.
|
|
@@ -653,7 +732,7 @@ export class AtomicTransactionComposer {
|
|
|
653
732
|
for (const [txnIndex, method] of this.methodCalls) {
|
|
654
733
|
const txID = txIDs[txnIndex];
|
|
655
734
|
|
|
656
|
-
|
|
735
|
+
let methodResult: ABIResult = {
|
|
657
736
|
txID,
|
|
658
737
|
rawReturnValue: new Uint8Array(),
|
|
659
738
|
method,
|
|
@@ -665,26 +744,12 @@ export class AtomicTransactionComposer {
|
|
|
665
744
|
? confirmedTxnInfo
|
|
666
745
|
: // eslint-disable-next-line no-await-in-loop
|
|
667
746
|
await client.pendingTransactionInformation(txID).do();
|
|
668
|
-
methodResult.txInfo = pendingInfo;
|
|
669
|
-
if (method.returns.type !== 'void') {
|
|
670
|
-
const logs: string[] = pendingInfo.logs || [];
|
|
671
|
-
if (logs.length === 0) {
|
|
672
|
-
throw new Error('App call transaction did not log a return value');
|
|
673
|
-
}
|
|
674
747
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
throw new Error('App call transaction did not log a return value');
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
methodResult.rawReturnValue = new Uint8Array(lastLog.slice(4));
|
|
684
|
-
methodResult.returnValue = method.returns.type.decode(
|
|
685
|
-
methodResult.rawReturnValue
|
|
686
|
-
);
|
|
687
|
-
}
|
|
748
|
+
methodResult = AtomicTransactionComposer.parseMethodResponse(
|
|
749
|
+
method,
|
|
750
|
+
methodResult,
|
|
751
|
+
pendingInfo
|
|
752
|
+
);
|
|
688
753
|
} catch (err) {
|
|
689
754
|
methodResult.decodeError = err;
|
|
690
755
|
}
|
|
@@ -698,4 +763,46 @@ export class AtomicTransactionComposer {
|
|
|
698
763
|
methodResults,
|
|
699
764
|
};
|
|
700
765
|
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Parses a single ABI Method transaction log into a ABI result object.
|
|
769
|
+
*
|
|
770
|
+
* @param method
|
|
771
|
+
* @param methodResult
|
|
772
|
+
* @param pendingInfo
|
|
773
|
+
* @returns An ABIResult object
|
|
774
|
+
*/
|
|
775
|
+
static parseMethodResponse(
|
|
776
|
+
method: ABIMethod,
|
|
777
|
+
methodResult: ABIResult,
|
|
778
|
+
pendingInfo: Record<string, any>
|
|
779
|
+
): ABIResult {
|
|
780
|
+
const returnedResult: ABIResult = methodResult;
|
|
781
|
+
try {
|
|
782
|
+
returnedResult.txInfo = pendingInfo;
|
|
783
|
+
if (method.returns.type !== 'void') {
|
|
784
|
+
const logs: string[] = pendingInfo.logs || [];
|
|
785
|
+
if (logs.length === 0) {
|
|
786
|
+
throw new Error('App call transaction did not log a return value');
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
const lastLog = Buffer.from(logs[logs.length - 1], 'base64');
|
|
790
|
+
if (
|
|
791
|
+
lastLog.byteLength < 4 ||
|
|
792
|
+
!lastLog.slice(0, 4).equals(RETURN_PREFIX)
|
|
793
|
+
) {
|
|
794
|
+
throw new Error('App call transaction did not log a return value');
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
returnedResult.rawReturnValue = new Uint8Array(lastLog.slice(4));
|
|
798
|
+
returnedResult.returnValue = method.returns.type.decode(
|
|
799
|
+
methodResult.rawReturnValue
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
} catch (err) {
|
|
803
|
+
returnedResult.decodeError = err;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
return returnedResult;
|
|
807
|
+
}
|
|
701
808
|
}
|
package/src/encoding/encoding.ts
CHANGED
|
@@ -33,6 +33,18 @@ function containsEmpty(obj: Record<string | number | symbol, any>) {
|
|
|
33
33
|
return { containsEmpty: false, firstEmptyKey: undefined };
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* rawEncode encodes objects using msgpack, regardless of whether there are
|
|
38
|
+
* empty or 0 value fields.
|
|
39
|
+
* @param obj - a dictionary to be encoded. May or may not contain empty or 0 values.
|
|
40
|
+
* @returns msgpack representation of the object
|
|
41
|
+
*/
|
|
42
|
+
export function rawEncode(obj: Record<string | number | symbol, any>) {
|
|
43
|
+
// enable the canonical option
|
|
44
|
+
const options = { sortKeys: true };
|
|
45
|
+
return msgpack.encode(obj, options);
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
/**
|
|
37
49
|
* encode encodes objects using msgpack
|
|
38
50
|
* @param obj - a dictionary to be encoded. Must not contain empty or 0 values.
|
|
@@ -47,8 +59,7 @@ export function encode(obj: Record<string | number | symbol, any>) {
|
|
|
47
59
|
}
|
|
48
60
|
|
|
49
61
|
// enable the canonical option
|
|
50
|
-
|
|
51
|
-
return msgpack.encode(obj, options);
|
|
62
|
+
return rawEncode(obj);
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
export function decode(buffer: ArrayLike<number>) {
|
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/signer.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transaction } from './transaction';
|
|
1
|
+
import { encodeUnsignedSimulateTransaction, Transaction } from './transaction';
|
|
2
2
|
import Account from './types/account';
|
|
3
3
|
import { LogicSigAccount, signLogicSigTransactionObject } from './logicsig';
|
|
4
4
|
import { MultisigMetadata } from './types/multisig';
|
|
@@ -80,6 +80,23 @@ export function makeMultiSigAccountTransactionSigner(
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Create a makeEmptyTransactionSigner that does not specify any signer or
|
|
85
|
+
* signing capabilities. This should only be used to simulate transactions.
|
|
86
|
+
*/
|
|
87
|
+
export function makeEmptyTransactionSigner(): TransactionSigner {
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
89
|
+
return (txnGroup: Transaction[], indexesToSign: number[]) => {
|
|
90
|
+
const unsigned: Uint8Array[] = [];
|
|
91
|
+
|
|
92
|
+
for (const index of indexesToSign) {
|
|
93
|
+
unsigned.push(encodeUnsignedSimulateTransaction(txnGroup[index]));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return Promise.resolve(unsigned);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
83
100
|
/** Represents an unsigned transactions and a signer that can authorize that transaction. */
|
|
84
101
|
export interface TransactionWithSigner {
|
|
85
102
|
/** An unsigned transaction */
|
package/src/transaction.ts
CHANGED
|
@@ -1278,6 +1278,23 @@ export class Transaction implements TransactionStorageStructure {
|
|
|
1278
1278
|
}
|
|
1279
1279
|
}
|
|
1280
1280
|
|
|
1281
|
+
/**
|
|
1282
|
+
* encodeUnsignedSimulateTransaction takes a txnBuilder.Transaction object,
|
|
1283
|
+
* converts it into a SignedTransaction-like object, and converts it to a Buffer.
|
|
1284
|
+
*
|
|
1285
|
+
* Note: this function should only be used to simulate unsigned transactions.
|
|
1286
|
+
*
|
|
1287
|
+
* @param transactionObject - Transaction object to simulate.
|
|
1288
|
+
*/
|
|
1289
|
+
export function encodeUnsignedSimulateTransaction(
|
|
1290
|
+
transactionObject: Transaction
|
|
1291
|
+
) {
|
|
1292
|
+
const objToEncode: EncodedSignedTransaction = {
|
|
1293
|
+
txn: transactionObject.get_obj_for_encoding(),
|
|
1294
|
+
};
|
|
1295
|
+
return encoding.encode(objToEncode);
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1281
1298
|
/**
|
|
1282
1299
|
* encodeUnsignedTransaction takes a completed txnBuilder.Transaction object, such as from the makeFoo
|
|
1283
1300
|
* family of transactions, and converts it to a Buffer
|
|
@@ -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
|
*/
|
|
@@ -45,10 +45,10 @@ export type TransactionBase =
|
|
|
45
45
|
* - A: Additional parameters on top of the base transaction parameters
|
|
46
46
|
* - O: A set of overwrites for transaction parameters
|
|
47
47
|
*/
|
|
48
|
-
export type ConstructTransaction<
|
|
49
|
-
|
|
50
|
-
O
|
|
51
|
-
>;
|
|
48
|
+
export type ConstructTransaction<
|
|
49
|
+
A = {},
|
|
50
|
+
O extends Partial<TransactionBase & A> = {}
|
|
51
|
+
> = DistributiveOverwrite<TransactionBase & A, O>;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Only accept transaction objects that include suggestedParams as an object
|
package/src/types/utils.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type Overwrite<T, U extends Partial<T>> = Pick<
|
|
|
27
27
|
/**
|
|
28
28
|
* Same as Overwrite, but will distribute the Overwrite over unions
|
|
29
29
|
*/
|
|
30
|
-
export type DistributiveOverwrite<T, K
|
|
30
|
+
export type DistributiveOverwrite<T, K extends Partial<T>> = T extends unknown
|
|
31
31
|
? Overwrite<T, K>
|
|
32
32
|
: never;
|
|
33
33
|
|