Skip to content

Commit f7f6182

Browse files
Merge pull request #159 from ElrondNetwork/better-interactions
Breaking changes (erdjs 10): improve contract interactions and interpretation of contract results
2 parents 8612618 + bbb2a56 commit f7f6182

Some content is hidden

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

63 files changed

+1379
-838
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish erdjs (alpha / beta)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
channel:
7+
type: choice
8+
description: NPM channel
9+
options:
10+
- alpha
11+
- beta
12+
13+
jobs:
14+
publish-npm:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: actions/setup-node@v1
19+
with:
20+
node-version: 12
21+
registry-url: https://registry.npmjs.org/
22+
23+
- run: npm ci
24+
- run: npm test
25+
26+
- name: Publish to npmjs
27+
env:
28+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
29+
run: npm publish --access=public --tag=${{ github.event.inputs.channel }}

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,36 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
77
## Unreleased
88
- TBD
99

10+
## [10.0.0]
11+
- [Breaking changes: improve contract interactions and interpretation of contract results](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/159)
12+
13+
**Breaking changes**
14+
15+
- `ExecutionResultsBundle` and `QueryResponseBundle` have been removed, and replaced by `TypedOutcomeBundle` (and its untyped counterpart, `UntypedOutcomeBundle`).
16+
- `SmartContractResults` has been changed to not use the concepts `immediate result` and `resulting calls` anymore. Instead, interpreting `SmartContractResults.items` is now the responsibility of the `ResultsParser` (on which the contract controllers depend).
17+
- Redesigned `QueryResponse`, changed most of its public interface. Results interpretation is now the responsibility of the results parser, called by the smart contract controllers.
18+
- `interpretQueryResponse()` and `interpretExecutionResults()` do not exist on the `Interaction` object anymore. Now, querying / executing an interaction against the controller will return the interpreted results.
19+
- `TokenIdentifierValue` is constructed using a `string`, not a `buffer`. Its `valueOf()` is now a string, as well.
20+
- The `Interaction` constructor does not receive the `interpretingFunction` parameter anymore.
21+
- `Interaction.getInterpretingFunction()` and `Interaction.getExecutingFunction()` have been removed, replaced by `Interaction.getFunction()`.
22+
- `DefaultInteractionRunner` has been removed, and replaced by **smart contract controllers**.
23+
- `StrictChecker` has been renamed to `InteractionChecker`. It's public interface - the function `checkInteraction()` - has changed as well (it also requires the endpoint definition now, as a second parameter).
24+
- The functions `getReceipt()`, `getSmartContractResults()` and `getLogs()` of `TransactionOnNetwork` have been removed. The underlying properties are now public.
25+
- Renamed `OptionValue.newMissingType()` to `OptionValue.newMissingTyped()`
26+
- Queries with a return code different than `Ok` do not automatically throw an exception anymore (`assertSuccess()` has to be called explicitly in order to throw).
27+
28+
**Other changes**
29+
30+
- `SmartContract`, in addition to `methods`, now also has a `methodAuto` object that allows one to create interactions without explicitly specifying the types of the arguments. Automatic type inference (within erdjs' typesystem) is leveraged. The type inference system was implemented in the past, in the `nativeSerializer` component - PR https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/9 by @claudiu725.
31+
- Added utility function `getFieldValue()` on `Struct` and `EnumValue`.
32+
- Refactoring in the `networkProvider` package (under development, in order to merge the provider interfaces under a single one)
33+
- Added utility function `Interaction.useThenIncrementNonceOf()`
34+
- Fixed `nativeSerializer` to not depend on `SmartContract`, `ContractWrapper` and `TestWallet` anymore (gathered under an interface).
35+
- Replaced the old `lottery-egld` with the new `lottery-esdt` in integration tests.
36+
- Added missing tests for some components: `nativeSerializer`, `struct`, `enum`.
37+
- Added utility function `OptionalValue.newMissing()`. Added "fake" covariance wrt. "null type parameter" (when value is missing) on `OptionalType`.
38+
- Added utility functions (typed value factories): `createListOfAddresses`, `createListOfTokenIdentifiers`.
39+
1040
## [9.2.3]
1141
- [Fix log level in transaction watcher.](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/160)
1242

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ Elrond SDK for JavaScript and TypeScript (written in TypeScript).
1818

1919
The most comprehensive usage examples are captured within the unit and the integration tests. Specifically, in the `*.spec.ts` files of the source code. For example:
2020

21-
- [transaction.dev.net.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/transaction.dev.net.spec.ts)
21+
- [transaction.local.net.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/transaction.local.net.spec.ts)
2222
- [address.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/address.spec.ts)
2323
- [transactionPayloadBuilders.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/smartcontracts/transactionPayloadBuilders.spec.ts)
2424
- [smartContract.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/smartcontracts/smartContract.spec.ts)
25-
- [smartContract.dev.net.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/smartcontracts/smartContract.dev.net.spec.ts)
25+
- [smartContract.local.net.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/smartcontracts/smartContract.local.net.spec.ts)
2626
- [query.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/smartcontracts/query.spec.ts)
2727
- [query.main.net.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/smartcontracts/query.main.net.spec.ts)
2828

2929
For advanced smart contract interaction, using ABIs, please see the following test files:
3030

31-
- [interaction.dev.net.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/smartcontracts/interaction.dev.net.spec.ts)
31+
- [interaction.local.net.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/smartcontracts/interaction.local.net.spec.ts)
3232
- [abiRegistry.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/smartcontracts/typesystem/abiRegistry.spec.ts)
3333
- [argSerializer.spec.ts](https://github.com/ElrondNetwork/elrond-sdk-erdjs/tree/main/src/smartcontracts/argSerializer.spec.ts)
3434

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elrondnetwork/erdjs",
3-
"version": "9.2.3",
3+
"version": "10.0.0-beta.1",
44
"description": "Smart Contracts interaction framework",
55
"main": "out/index.js",
66
"types": "out/index.d.js",

src/errors.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,33 @@ export class ErrTypingSystem extends Err {
409409
}
410410
}
411411

412+
/**
413+
* Signals a missing field on a struct.
414+
*/
415+
export class ErrMissingFieldOnStruct extends Err {
416+
public constructor(fieldName: string, structName: string) {
417+
super(`field ${fieldName} does not exist on struct ${structName}`);
418+
}
419+
}
420+
421+
/**
422+
* Signals a missing field on an enum.
423+
*/
424+
export class ErrMissingFieldOnEnum extends Err {
425+
public constructor(fieldName: string, enumName: string) {
426+
super(`field ${fieldName} does not exist on enum ${enumName}`);
427+
}
428+
}
429+
430+
/**
431+
* Signals an error when parsing the contract results.
432+
*/
433+
export class ErrCannotParseContractResults extends Err {
434+
public constructor(details: string) {
435+
super(`cannot parse contract results: ${details}`);
436+
}
437+
}
438+
412439
/**
413440
* Signals a generic codec (encode / decode) error.
414441
*/

src/networkProvider/contractResults.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Hash } from "../hash";
55
import { IContractQueryResponse, IContractResultItem, IContractResults } from "./interface";
66
import { GasLimit, GasPrice } from "../networkParams";
77
import { Nonce } from "../nonce";
8-
import { ArgSerializer, EndpointDefinition, MaxUint64, ReturnCode, TypedValue } from "../smartcontracts";
8+
import { MaxUint64, ReturnCode } from "../smartcontracts";
99
import { TransactionHash } from "../transaction";
1010

1111
export class ContractResults implements IContractResults {
@@ -80,16 +80,6 @@ export class ContractResultItem implements IContractResultItem {
8080

8181
return item;
8282
}
83-
84-
getOutputUntyped(): Buffer[] {
85-
// TODO: Decide how to parse "data" (immediate results vs. other results).
86-
throw new Error("Method not implemented.");
87-
}
88-
89-
getOutputTyped(_endpointDefinition: EndpointDefinition): TypedValue[] {
90-
// TODO: Decide how to parse "data" (immediate results vs. other results).
91-
throw new Error("Method not implemented.");
92-
}
9383
}
9484

9585
export class ContractQueryResponse implements IContractQueryResponse {
@@ -110,14 +100,7 @@ export class ContractQueryResponse implements IContractQueryResponse {
110100
return response;
111101
}
112102

113-
getOutputUntyped(): Buffer[] {
114-
let buffers = this.returnData.map((item) => Buffer.from(item || "", "base64"));
115-
return buffers;
116-
}
117-
118-
getOutputTyped(endpointDefinition: EndpointDefinition): TypedValue[] {
119-
let buffers = this.getOutputUntyped();
120-
let values = new ArgSerializer().buffersToValues(buffers, endpointDefinition!.output);
121-
return values;
103+
getReturnDataParts(): Buffer[] {
104+
return this.returnData.map((item) => Buffer.from(item || ""));
122105
}
123106
}

src/networkProvider/interface.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { NetworkStake } from "../networkStake";
99
import { NetworkStatus } from "../networkStatus";
1010
import { Nonce } from "../nonce";
1111
import { Signature } from "../signature";
12-
import { EndpointDefinition, Query, ReturnCode, TypedValue } from "../smartcontracts";
12+
import { Query, ReturnCode } from "../smartcontracts";
1313
import { Stats } from "../stats";
1414
import { Transaction, TransactionHash, TransactionStatus } from "../transaction";
1515
import { TransactionLogs } from "../transactionLogs";
@@ -204,19 +204,15 @@ export interface IContractResultItem {
204204
gasPrice: GasPrice;
205205
callType: number;
206206
returnMessage: string;
207-
208-
getOutputUntyped(): Buffer[];
209-
getOutputTyped(endpointDefinition: EndpointDefinition): TypedValue[];
210207
}
211208

212209
export interface IContractQueryResponse {
213210
returnData: string[];
214211
returnCode: ReturnCode;
215212
returnMessage: string;
216213
gasUsed: GasLimit;
217-
218-
getOutputUntyped(): Buffer[];
219-
getOutputTyped(endpointDefinition: EndpointDefinition): TypedValue[];
214+
215+
getReturnDataParts(): Buffer[];
220216
}
221217

222218
export interface IContractSimulation {

src/networkProvider/providers.dev.net.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ describe("test network providers on devnet: Proxy and API", function () {
227227
let proxyResponse = await proxyProvider.queryContract(query);
228228

229229
assert.deepEqual(apiResponse, proxyResponse);
230-
assert.deepEqual(apiResponse.getOutputUntyped(), proxyResponse.getOutputUntyped());
230+
assert.deepEqual(apiResponse.getReturnDataParts(), proxyResponse.getReturnDataParts());
231231

232232
// Query: increment counter
233233
query = new Query({
@@ -240,7 +240,7 @@ describe("test network providers on devnet: Proxy and API", function () {
240240
proxyResponse = await proxyProvider.queryContract(query);
241241

242242
assert.deepEqual(apiResponse, proxyResponse);
243-
assert.deepEqual(apiResponse.getOutputUntyped(), proxyResponse.getOutputUntyped());
243+
assert.deepEqual(apiResponse.getReturnDataParts(), proxyResponse.getReturnDataParts());
244244

245245
// Query: issue ESDT
246246
query = new Query({
@@ -260,6 +260,6 @@ describe("test network providers on devnet: Proxy and API", function () {
260260
proxyResponse = await proxyProvider.queryContract(query);
261261

262262
assert.deepEqual(apiResponse, proxyResponse);
263-
assert.deepEqual(apiResponse.getOutputUntyped(), proxyResponse.getOutputUntyped());
263+
assert.deepEqual(apiResponse.getReturnDataParts(), proxyResponse.getReturnDataParts());
264264
});
265265
});

src/proxyProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class ProxyProvider implements IProvider {
7070
return this.doPostGeneric("vm-values/query", data, (response) =>
7171
QueryResponse.fromHttpResponse(response.data || response.vmOutput)
7272
);
73-
} catch (err) {
73+
} catch (err: any) {
7474
throw errors.ErrContractQuery.increaseSpecificity(err);
7575
}
7676
}

0 commit comments

Comments
 (0)