Skip to content

Commit

Permalink
Merge pull request #101 from OriginTrail/feature/allowance
Browse files Browse the repository at this point in the history
Add function for getting current allowance and wallet balances
  • Loading branch information
NZT48 authored Sep 6, 2023
2 parents ec4b430 + 2967e2b commit 4ea85ad
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/dkg.min.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions managers/asset-operations-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ class AssetOperationsManager {
};
}

async getCurrentAllowance(options = {}) {
const blockchain = this.inputService.getBlockchain(options);

const serviceAgreementV1Address = await this.blockchainService.getContractAddress(
'ServiceAgreementV1',
blockchain,
);

const allowance = await this.blockchainService.callContractFunction(
'Token',
'allowance',
[blockchain.publicKey, serviceAgreementV1Address],
blockchain,
);

return allowance;
}

/**
* Creates a new asset.
* @async
Expand Down
8 changes: 7 additions & 1 deletion managers/blockchain-operations-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ class BlockchainOperationsManager {
this.inputService = services.inputService;
}

async getGasPrice(blockchain){
async getGasPrice(options = {}){
const blockchain = this.inputService.getBlockchain(options);
return this.blockchainService.getGasPrice(blockchain);
}

async getWalletBalances(options = {}){
const blockchain = this.inputService.getBlockchain(options);
return this.blockchainService.getWalletBalances(blockchain);
}
}

module.exports = BlockchainOperationsManager;
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": "dkg.js",
"version": "6.0.9",
"version": "6.0.10",
"description": "Javascript library for interaction with the OriginTrail Decentralized Knowledge Graph",
"main": "index.js",
"scripts": {
Expand Down
18 changes: 18 additions & 0 deletions services/blockchain-service/blockchain-service-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,24 @@ class BlockchainServiceBase {
return gasPrice;
}

async getWalletBalances(blockchain) {
const web3Instance = await this.getWeb3Instance(blockchain);
const publicKey = await this.getPublicKey(blockchain);

const blockchainTokenBalance = await web3Instance.eth.getBalance(publicKey);
const tracBalance = await this.callContractFunction(
'Token',
'balanceOf',
[await this.getPublicKey(blockchain)],
blockchain,
);

return {
blockchainToken: blockchainTokenBalance,
trac: tracBalance
}
}

async getLatestBlock(blockchain) {
const web3 = await this.getWeb3Instance(blockchain);
const blockNumber = await web3.eth.getBlockNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ class NodeBlockchainService extends BlockchainServiceBase {
if (
!transactionRetried &&
blockchain.handleNotMinedError &&
e.message.includes('Transaction was not mined')
(
e.message.includes('Transaction was not mined')
|| e.message.includes('Already known')
)
) {
transactionRetried = true;
// eslint-disable-next-line no-param-reassign
Expand Down

0 comments on commit 4ea85ad

Please sign in to comment.