Skip to content

Commit

Permalink
Merge pull request #114 from rsksmart/fix/refactor-for-rsk-contract-p…
Browse files Browse the repository at this point in the history
…arser-usage

fix: update for new rsk-contract-parser's bridge abi handling
  • Loading branch information
nicov-iov authored Nov 7, 2023
2 parents e6577bf + ba7f8d8 commit 6738995
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
3 changes: 2 additions & 1 deletion dist/services/classes/BcStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class BcStats extends _BlocksBase.BlocksBase {
try {
const { nod3, initConfig } = this;
const address = initConfig.nativeContracts.bridge;
const abi = _rskContractParser.abi.bridge;
const bitcoinNetwork = this.net.id;
const abi = _rskContractParser.abi.bridge({ bitcoinNetwork });
const contract = (0, _rskContractParser.Contract)(abi, { address, nod3 });
const res = await contract.call(method, params);
return res;
Expand Down
10 changes: 5 additions & 5 deletions dist/services/classes/Contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Contract extends _BcThing.BcThing {
try {
let { deployedCode, fetched } = this;
if (fetched) return this.getData();
let contract = await this.setContract();
let contract = await this.setContract(this.block.number);
if (!this.isNative) {
// new contracts
if (!this.data.contractInterfaces) {
Expand Down Expand Up @@ -70,26 +70,26 @@ class Contract extends _BcThing.BcThing {
}
}

async getParser() {
async getParser(txBlockNumber) {
try {
let { nod3, initConfig, log } = this;
if (!this.parser) {
let abi = await this.getAbi();
this.parser = new _rskContractParser.default({ abi, nod3, initConfig, log });
this.parser = new _rskContractParser.default({ abi, nod3, initConfig, log, txBlockNumber });
}
return this.parser;
} catch (err) {
return Promise.reject(err);
}
}

async setContract() {
async setContract(txBlockNumber) {
try {
let { address, contract } = this;
if (contract) return contract;
// get abi
let abi = await this.getAbi();
let parser = await this.getParser();
let parser = await this.getParser(txBlockNumber);
this.contract = parser.makeContract(address, abi);
return this.contract;
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion dist/services/classes/Tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class Tx extends _BcThing.BcThing {
events[index] = (0, _Event.formatEvent)(log, tx);
} else {
contracts[address] = contract;
let parser = await contract.getParser();
let parser = await contract.getParser(tx.blockNumber);
let [event] = parser.parseTxLogs([log]);
events[index] = (0, _Event.formatEvent)(event, tx);
const { _addresses } = event;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"homepage": "https://github.com/rsksmart/rsk-explorer-api",
"dependencies": {
"@rsksmart/nod3": "^0.5.0",
"@rsksmart/rsk-contract-parser": "^0.0.12",
"@rsksmart/rsk-contract-parser": "^1.0.0",
"@rsksmart/rsk-js-cli": "^1.0.0",
"@rsksmart/rsk-utils": "^1.1.0",
"bignumber.js": "^7.2.1",
Expand Down
3 changes: 2 additions & 1 deletion src/services/classes/BcStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export class BcStats extends BlocksBase {
try {
const { nod3, initConfig } = this
const address = initConfig.nativeContracts.bridge
const abi = ABI.bridge
const bitcoinNetwork = this.net.id
const abi = ABI.bridge({ bitcoinNetwork })
const contract = Contract(abi, { address, nod3 })
const res = await contract.call(method, params)
return res
Expand Down
10 changes: 5 additions & 5 deletions src/services/classes/Contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Contract extends BcThing {
try {
let { deployedCode, fetched } = this
if (fetched) return this.getData()
let contract = await this.setContract()
let contract = await this.setContract(this.block.number)
if (!this.isNative) {
// new contracts
if (!this.data.contractInterfaces) {
Expand Down Expand Up @@ -70,26 +70,26 @@ class Contract extends BcThing {
}
}

async getParser () {
async getParser (txBlockNumber) {
try {
let { nod3, initConfig, log } = this
if (!this.parser) {
let abi = await this.getAbi()
this.parser = new ContractParser({ abi, nod3, initConfig, log })
this.parser = new ContractParser({ abi, nod3, initConfig, log, txBlockNumber })
}
return this.parser
} catch (err) {
return Promise.reject(err)
}
}

async setContract () {
async setContract (txBlockNumber) {
try {
let { address, contract } = this
if (contract) return contract
// get abi
let abi = await this.getAbi()
let parser = await this.getParser()
let parser = await this.getParser(txBlockNumber)
this.contract = parser.makeContract(address, abi)
return this.contract
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/classes/Tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class Tx extends BcThing {
events[index] = formatEvent(log, tx)
} else {
contracts[address] = contract
let parser = await contract.getParser()
let parser = await contract.getParser(tx.blockNumber)
let [event] = parser.parseTxLogs([log])
events[index] = formatEvent(event, tx)
const { _addresses } = event
Expand Down

0 comments on commit 6738995

Please sign in to comment.