Skip to content

Commit

Permalink
Merge pull request #198 from ERC725Alliance/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugoo authored Jun 24, 2022
2 parents 303720a + 2904d9b commit 714495f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 33 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.14.2](https://github.com/ERC725Alliance/erc725.js/compare/v0.14.1...v0.14.2) (2022-06-24)

### Bug Fixes

* Update JsonRpc eth_call parameters ([470e846](https://github.com/ERC725Alliance/erc725.js/commit/470e8461e581f0763fe3fddc8f604cc55002f7a1))


### [0.14.1](https://github.com/ERC725Alliance/erc725.js/compare/v0.14.0...v0.14.1) (2022-06-15)

Minor update to update the LSP-2 schemas.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@erc725/erc725.js",
"version": "0.14.1",
"version": "0.14.2",
"description": "Library to interact with ERC725 smart contracts",
"main": "build/main/src/index.js",
"typings": "build/main/src/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/provider-wrapper-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export function constructJSONRPC(
{
to: address,
gas: METHODS[method].gas,
gasPrice: METHODS[method].gasPrice,
value: METHODS[method].value,
data,
},
'latest',
],
id: idCount,
};
Expand Down
38 changes: 20 additions & 18 deletions src/providers/ethereumProviderWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
METHODS,
} from '../lib/constants';
import { decodeResult as decodeResultUtils } from '../lib/provider-wrapper-utils';
import { JsonRpcEthereumProvider } from '../types/JsonRpc';
import { JsonRpcEthereumProviderParams } from '../types/JsonRpc';
import { Method } from '../types/Method';
import { ProviderTypes } from '../types/provider';

Expand All @@ -53,7 +53,7 @@ export class EthereumProviderWrapper {

async getOwner(address: string) {
const params = this.constructJSONRPC(address, Method.OWNER);
const result = await this.callContract([params]);
const result = await this.callContract(params);
if (result.error) {
throw result.error;
}
Expand Down Expand Up @@ -102,13 +102,13 @@ export class EthereumProviderWrapper {
async supportsInterface(address: string, interfaceId: string) {
return this.decodeResult(
Method.SUPPORTS_INTERFACE,
await this.callContract([
await this.callContract(
this.constructJSONRPC(
address,
Method.SUPPORTS_INTERFACE,
`${interfaceId}${'00000000000000000000000000000000000000000000000000000000'}`,
),
]),
),
);
}

Expand All @@ -125,9 +125,9 @@ export class EthereumProviderWrapper {
[hash, signature],
);

const result = await this.callContract([
const result = await this.callContract(
this.constructJSONRPC(address, Method.IS_VALID_SIGNATURE, encodedParams),
]);
);

if (result.error) {
throw result.error;
Expand Down Expand Up @@ -172,13 +172,13 @@ export class EthereumProviderWrapper {
address: string,
keyHashes: string[],
): Promise<GetDataReturn[]> {
const encodedResults = await this.callContract([
const encodedResults = await this.callContract(
this.constructJSONRPC(
address,
Method.GET_DATA,
abiCoder.encodeParameter('bytes32[]', keyHashes),
),
]);
);

const decodedValues = this.decodeResult(Method.GET_DATA, encodedResults);

Expand All @@ -195,9 +195,9 @@ export class EthereumProviderWrapper {
// Here we could use `getDataMultiple` instead of sending multiple calls to `getData`
// But this is already legacy and it won't be used anymore..
const encodedResultsPromises = keyHashes.map((keyHash) =>
this.callContract([
this.callContract(
this.constructJSONRPC(address, Method.GET_DATA_LEGACY, keyHash),
]),
),
);

const decodedResults = await Promise.all(encodedResultsPromises);
Expand All @@ -213,18 +213,20 @@ export class EthereumProviderWrapper {
address: string,
method: Method,
methodParam?: string,
): JsonRpcEthereumProvider {
): (JsonRpcEthereumProviderParams | string)[] {
const data = methodParam
? METHODS[method].sig + methodParam.replace('0x', '')
: METHODS[method].sig;

return {
to: address,
gas: METHODS[method].gas,
gasPrice: METHODS[method].gasPrice,
value: METHODS[method].value,
data,
};
return [
{
to: address,
value: METHODS[method].value,
gas: METHODS[method].gas,
data,
},
'latest',
];
}

private async callContract(params: any) {
Expand Down
17 changes: 9 additions & 8 deletions src/providers/web3ProviderWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,15 @@ export class Web3ProviderWrapper {
address: string,
interfaceId: string,
): Promise<boolean> {
return decodeResult(
Method.SUPPORTS_INTERFACE,
await this.callContract(
constructJSONRPC(
address,
Method.SUPPORTS_INTERFACE,
`${interfaceId}${'00000000000000000000000000000000000000000000000000000000'}`,
),
const result = await this.callContract(
constructJSONRPC(
address,
Method.SUPPORTS_INTERFACE,
`${interfaceId}${'00000000000000000000000000000000000000000000000000000000'}`,
),
);

return decodeResult(Method.SUPPORTS_INTERFACE, result);
}

/**
Expand Down Expand Up @@ -200,6 +199,7 @@ export class Web3ProviderWrapper {
constructJSONRPC(address, Method.GET_DATA_LEGACY, keyHashes[index]),
);
}

const results: any = await this.callContract(payload);

return payload.map<GetDataReturn>((payloadCall, index) => ({
Expand All @@ -215,6 +215,7 @@ export class Web3ProviderWrapper {
return new Promise((resolve, reject) => {
// Send old web3 method with callback to resolve promise
// This is deprecated: https://docs.metamask.io/guide/ethereum-provider.html#ethereum-send-deprecated

this.provider.send(payload, (e, r) => {
if (e) {
reject(e);
Expand Down
5 changes: 2 additions & 3 deletions src/types/JsonRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ export interface JsonRpc {
{
to: string;
gas: string;
gasPrice: string;
value: string;
data;
},
'latest',
];
id: number;
}

export interface JsonRpcEthereumProvider {
export interface JsonRpcEthereumProviderParams {
to: string;
gas: string;
gasPrice: string;
value: string;
data;
}

0 comments on commit 714495f

Please sign in to comment.