Skip to content

Commit b4af128

Browse files
authored
Merge pull request #272 from OriginTrail/fix/approve-called-without-sufficient-TRAC
Fix for approve called without sufficient trac
2 parents a09f3dc + 7c4f437 commit b4af128

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
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": "dkg.js",
3-
"version": "8.2.3",
3+
"version": "8.2.4",
44
"description": "Javascript library for interaction with the OriginTrail Decentralized Knowledge Graph",
55
"main": "index.js",
66
"exports": {

services/blockchain-service/blockchain-service-base.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,25 @@ export default class BlockchainServiceBase {
510510
if (requestData?.paymaster && requestData?.paymaster !== ZERO_ADDRESS) {
511511
// Handle the case when payer is passed
512512
} else {
513+
const senderBalance = await this.callContractFunction(
514+
'Token',
515+
'balanceOf',
516+
[sender],
517+
blockchain,
518+
);
519+
520+
if (BigInt(senderBalance) < BigInt(requestData.tokenAmount)) {
521+
const balance = Number(senderBalance) / 1e18;
522+
const required = Number(requestData.tokenAmount) / 1e18;
523+
524+
throw new Error(
525+
`Insufficient TRAC token balance to publish. ` +
526+
`Wallet ${sender} has ${balance} TRAC, ` +
527+
`but the publish operation requires ${required} TRAC. ` +
528+
`Please fund your wallet with more TRAC tokens to proceed.`,
529+
);
530+
}
531+
513532
await this.increaseKnowledgeCollectionAllowance(
514533
sender,
515534
requestData.tokenAmount,

0 commit comments

Comments
 (0)