Skip to content

Commit

Permalink
Merge pull request #159 from ElrondNetwork/better-interactions
Browse files Browse the repository at this point in the history
Breaking changes (erdjs 10): improve contract interactions and interpretation of contract results
  • Loading branch information
andreibancioiu authored Mar 24, 2022
2 parents 790a352 + 41084c6 commit be7ba70
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 30 deletions.
23 changes: 3 additions & 20 deletions src-network-providers/networkProvider/contractResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Hash } from "../hash";
import { IContractQueryResponse, IContractResultItem, IContractResults } from "./interface";
import { GasLimit, GasPrice } from "../networkParams";
import { Nonce } from "../nonce";
import { ArgSerializer, EndpointDefinition, MaxUint64, ReturnCode, TypedValue } from "../smartcontracts";
import { MaxUint64, ReturnCode } from "../smartcontracts";
import { TransactionHash } from "../transaction";

export class ContractResults implements IContractResults {
Expand Down Expand Up @@ -80,16 +80,6 @@ export class ContractResultItem implements IContractResultItem {

return item;
}

getOutputUntyped(): Buffer[] {
// TODO: Decide how to parse "data" (immediate results vs. other results).
throw new Error("Method not implemented.");
}

getOutputTyped(_endpointDefinition: EndpointDefinition): TypedValue[] {
// TODO: Decide how to parse "data" (immediate results vs. other results).
throw new Error("Method not implemented.");
}
}

export class ContractQueryResponse implements IContractQueryResponse {
Expand All @@ -110,14 +100,7 @@ export class ContractQueryResponse implements IContractQueryResponse {
return response;
}

getOutputUntyped(): Buffer[] {
let buffers = this.returnData.map((item) => Buffer.from(item || "", "base64"));
return buffers;
}

getOutputTyped(endpointDefinition: EndpointDefinition): TypedValue[] {
let buffers = this.getOutputUntyped();
let values = new ArgSerializer().buffersToValues(buffers, endpointDefinition!.output);
return values;
getReturnDataParts(): Buffer[] {
return this.returnData.map((item) => Buffer.from(item || ""));
}
}
10 changes: 3 additions & 7 deletions src-network-providers/networkProvider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NetworkStake } from "../networkStake";
import { NetworkStatus } from "../networkStatus";
import { Nonce } from "../nonce";
import { Signature } from "../signature";
import { EndpointDefinition, Query, ReturnCode, TypedValue } from "../smartcontracts";
import { Query, ReturnCode } from "../smartcontracts";
import { Stats } from "../stats";
import { Transaction, TransactionHash, TransactionStatus } from "../transaction";
import { TransactionLogs } from "../transactionLogs";
Expand Down Expand Up @@ -204,19 +204,15 @@ export interface IContractResultItem {
gasPrice: GasPrice;
callType: number;
returnMessage: string;

getOutputUntyped(): Buffer[];
getOutputTyped(endpointDefinition: EndpointDefinition): TypedValue[];
}

export interface IContractQueryResponse {
returnData: string[];
returnCode: ReturnCode;
returnMessage: string;
gasUsed: GasLimit;

getOutputUntyped(): Buffer[];
getOutputTyped(endpointDefinition: EndpointDefinition): TypedValue[];

getReturnDataParts(): Buffer[];
}

export interface IContractSimulation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe("test network providers on devnet: Proxy and API", function () {
let proxyResponse = await proxyProvider.queryContract(query);

assert.deepEqual(apiResponse, proxyResponse);
assert.deepEqual(apiResponse.getOutputUntyped(), proxyResponse.getOutputUntyped());
assert.deepEqual(apiResponse.getReturnDataParts(), proxyResponse.getReturnDataParts());

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

assert.deepEqual(apiResponse, proxyResponse);
assert.deepEqual(apiResponse.getOutputUntyped(), proxyResponse.getOutputUntyped());
assert.deepEqual(apiResponse.getReturnDataParts(), proxyResponse.getReturnDataParts());

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

assert.deepEqual(apiResponse, proxyResponse);
assert.deepEqual(apiResponse.getOutputUntyped(), proxyResponse.getOutputUntyped());
assert.deepEqual(apiResponse.getReturnDataParts(), proxyResponse.getReturnDataParts());
});
});

0 comments on commit be7ba70

Please sign in to comment.