Skip to content

Commit 9f4335d

Browse files
committed
Using DEBUG for ls-sdk debug logging
1 parent 8b1d011 commit 9f4335d

File tree

11 files changed

+152
-49
lines changed

11 files changed

+152
-49
lines changed

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
DEBUG='ls-sdk:*'
2+
13
ACCOUNT="0xc916cfe5c83dd4fc3c3b0bf2ec2d4e401782875e"
24
PASSPHRASE=""
35
RELAY_HUB=""

build/src/web3/latest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ module.exports.contractSendTx = function (web3, _ref9) {
321321
useGSN: useGSN || false,
322322
gas: estimatedGas
323323
}).on('transactionHash', function (txHash) {
324-
console.log("Tx executed: ", txHash);
324+
// console.log("Tx executed: ", txHash);
325325
}).on('receipt', function (txReceipt) {
326326
if (!txReceipt.status) {
327327
reject(new Error("Failed tx ".concat(txReceipt.hash)));

package-lock.json

Lines changed: 83 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lightstreams-js-sdk",
3-
"version": "0.16.3",
3+
"version": "0.17.0",
44
"description": "Lightstreams JS SDK for building mainstream DApps with support for Programmable Decentralized Private Storage.",
55
"author": "Gabriel Garrido",
66
"contributors": [
@@ -49,6 +49,7 @@
4949
"@openzeppelin/network": "0.2.9",
5050
"@openzeppelin/upgrades": "2.5.3",
5151
"cids": "^0.7.1",
52+
"debug": "^4.1.1",
5253
"entropy-string": "^4.2.0",
5354
"eth-ens-namehash": "^2.0.8",
5455
"ethereum-ens": "^0.7.7",

src/contracts/artist_token.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*/
66

77
const Web3Wrapper = require('../web3');
8+
const Debug = require('debug');
89

910
const artistTokenSc = require('../../build/contracts/ArtistToken.json');
1011
const fundingPoolSc = require('../../build/contracts/FundingPool.json');
1112
const wphtSc = require('../../build/contracts/WPHT.json');
13+
const logger = Debug('ls-sdk:contract:artistToken');
1214

1315
module.exports.deployFundingPool = async (web3, { from }) => {
1416
Web3Wrapper.validator.validateAddress("from", from);
@@ -24,7 +26,7 @@ module.exports.deployFundingPool = async (web3, { from }) => {
2426
}
2527
);
2628

27-
console.log(`FundingPool deployed at: ${receipt.contractAddress}`);
29+
logger(`FundingPool deployed at: ${receipt.contractAddress}`);
2830

2931
return receipt;
3032
};
@@ -119,7 +121,7 @@ module.exports.deployArtistToken = async (
119121
}
120122
);
121123

122-
console.log(`ArtistToken deployed at: ${receipt.contractAddress}`);
124+
logger(`ArtistToken deployed at: ${receipt.contractAddress}`);
123125
return receipt;
124126
};
125127

@@ -137,7 +139,7 @@ module.exports.isArtistTokenHatched = async (web3, { artistTokenAddr }) => {
137139
}
138140
);
139141

140-
console.log(`ArtistToken ${artistTokenAddr} is hatched: ${isHatched}`);
142+
logger(`ArtistToken ${artistTokenAddr} is hatched: ${isHatched}`);
141143

142144
return isHatched;
143145
};
@@ -149,7 +151,7 @@ module.exports.hatchArtistToken = async (web3, { from, artistTokenAddr, wphtAddr
149151
Web3Wrapper.validator.validateWeiBn("amountWeiBn", amountWeiBn);
150152

151153
const hatchingAmountInPHT = Web3Wrapper.utils.toPht(amountWeiBn);
152-
console.log(`Hatcher ${from} sent a hatch worth of ${hatchingAmountInPHT} PHT to artist token ${artistTokenAddr}`);
154+
logger(`Hatcher ${from} sent a hatch worth of ${hatchingAmountInPHT} PHT to artist token ${artistTokenAddr}`);
153155
if (runDepositFirst) {
154156
await Web3Wrapper.contractSendTx(
155157
web3,
@@ -195,7 +197,7 @@ module.exports.hatchArtistToken = async (web3, { from, artistTokenAddr, wphtAddr
195197
contributionInWPHT: hatchingAmountInPHT
196198
});
197199

198-
console.log(`Hatched completed, expected ${expectedArtistTokens} ArtistTokens`);
200+
logger(`Hatched completed, expected ${expectedArtistTokens} ArtistTokens`);
199201
return receipt;
200202
};
201203

@@ -213,7 +215,7 @@ module.exports.getArtistTokenTotalSupply = async (web3, { artistTokenAddr }) =>
213215
}
214216
);
215217

216-
console.log(`ArtistToken ${artistTokenAddr} total supply is: ${Web3Wrapper.utils.wei2pht(totalSupply)} PHT`);
218+
logger(`ArtistToken ${artistTokenAddr} total supply is: ${Web3Wrapper.utils.wei2pht(totalSupply)} PHT`);
217219

218220
return totalSupply;
219221
};
@@ -246,6 +248,19 @@ module.exports.transfer = async (web3, { artistTokenAddr, from, to, amountInBn }
246248
);
247249
};
248250

251+
module.exports.transferOwnership = async (web3, {artistTokenAddr, from, newOwnerAddr}) => {
252+
return await Web3Wrapper.contractSendTx(
253+
web3,
254+
{
255+
to: artistTokenAddr,
256+
from: from,
257+
method: 'transferOwnership',
258+
abi: artistTokenSc.abi,
259+
params: [newOwnerAddr]
260+
}
261+
);
262+
};
263+
249264
module.exports.approve = async (web3, { artistTokenAddr, from, to, amountInBn }) => {
250265
return await Web3Wrapper.contractSendTx(
251266
web3,
@@ -386,7 +401,7 @@ module.exports.getArtistTokenBalanceOf = async (web3, { artistTokenAddr, account
386401
}
387402
);
388403

389-
console.log(`Account ${accountAddr} has ${Web3Wrapper.utils.wei2pht(balance.toString())} ${symbol} of ArtistToken ${artistTokenAddr}`);
404+
logger(`Account ${accountAddr} has ${Web3Wrapper.utils.wei2pht(balance.toString())} ${symbol} of ArtistToken ${artistTokenAddr}`);
390405

391406
return Web3Wrapper.utils.toBN(balance);
392407
};
@@ -438,7 +453,7 @@ module.exports.buyArtistTokens = async (web3, { from, artistTokenAddr, wphtAddr,
438453

439454
const tokens = receipt.events['CurvedMint'].returnValues['amount'];
440455

441-
console.log(`Buyer ${from} purchased ${tokens.toString()} ${symbol} of ArtistToken ${artistTokenAddr}`);
456+
logger(`Buyer ${from} purchased ${tokens.toString()} ${symbol} of ArtistToken ${artistTokenAddr}`);
442457

443458
return Web3Wrapper.utils.toBN(tokens);
444459
};
@@ -465,7 +480,7 @@ module.exports.sellArtistTokens = async (web3, { from, artistTokenAddr, amountBn
465480

466481
const wphtReimbursement = receipt.events['CurvedBurn'].returnValues['reimbursement'];
467482

468-
console.log(`Account ${from} sold ${Web3Wrapper.utils.wei2pht(amountBn.toString())} ${symbol} of ArtistToken ${artistTokenAddr} for ${Web3Wrapper.utils.wei2pht(wphtReimbursement.toString())} WPHT`);
483+
logger(`Account ${from} sold ${Web3Wrapper.utils.wei2pht(amountBn.toString())} ${symbol} of ArtistToken ${artistTokenAddr} for ${Web3Wrapper.utils.wei2pht(wphtReimbursement.toString())} WPHT`);
469484

470485
return wphtReimbursement;
471486
};

src/contracts/profile.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
* Date: 14/08/19 15:44
44
* Copyright 2019 (c) Lightstreams, Granada
55
*/
6+
const Debug = require('debug');
67
const Web3Wrapper = require('../web3');
8+
79
const CID = require('cids');
810
const {
911
fundRecipient,
1012
isRelayHubDeployed,
1113
getRecipientFunds
1214
} = require('../gsn');
1315

14-
const {
15-
buyArtistTokens,
16-
transfer: transferIERC20Token,
17-
getBalanceOf
18-
} = require('./artist_token');
19-
2016
const factoryScJSON = require('../../build/contracts/GSNProfileFactory.json');
2117
const profileScJSON = require('../../build/contracts/GSNProfile.json');
18+
const logger = Debug('ls-sdk:contract:profile');
2219

2320
const cidPrefix = 'Qm';
2421
const cidLength = 46;
@@ -70,7 +67,7 @@ module.exports.initializeProfileFactory = async (web3, { contractAddr, relayHub,
7067
if (!txReceipt.status) {
7168
throw new Error(`ProfileFactory initialization failed`);
7269
} else {
73-
console.log(`Activated GSN for ProfileFactory instance for RelayHub ${relayHub}...`);
70+
logger(`Activated GSN for ProfileFactory instance for RelayHub ${relayHub}...`);
7471
}
7572

7673
// Step 3: Profile factory is funded via RelayHub
@@ -81,26 +78,26 @@ module.exports.initializeProfileFactory = async (web3, { contractAddr, relayHub,
8178
amountInPht: factoryFundingInPht
8279
});
8380

84-
console.log(`Recipient ${contractAddr} is sponsored by relayHub with ${factoryFundingInPht} PHTs...`);
81+
logger(`Recipient ${contractAddr} is sponsored by relayHub with ${factoryFundingInPht} PHTs...`);
8582

8683
// Step 4: Top up factory contract to fund new profile deployments
8784
await Web3Wrapper.sendTransaction(web3, { from, to: contractAddr, valueInPht: faucetFundingInPht });
88-
console.log(`Topped up ProfileFactory with ${faucetFundingInPht} PHTs to fund new profile creations...`);
85+
logger(`Topped up ProfileFactory with ${faucetFundingInPht} PHTs to fund new profile creations...`);
8986

9087
return contractAddr;
9188
};
9289

9390
module.exports.validateHasEnoughFundToDeployProfile = async(web3, { contractAddr }) => {
9491
const recipientFundsInWei = await getRecipientFunds(web3, { recipient: contractAddr });
9592
const recipientFundsInPht = Web3Wrapper.utils.toPht(`${recipientFundsInWei}`);
96-
console.log(`GSNProfileFactory recipient has ${recipientFundsInPht} PHT for GSN`);
93+
logger(`GSNProfileFactory recipient has ${recipientFundsInPht} PHT for GSN`);
9794
if (parseFloat(recipientFundsInPht) < 1.0) {
9895
throw new Error(`Not enough recipient funds: ${recipientFundsInPht} PHT`);
9996
}
10097

10198
const balanceInWei = await Web3Wrapper.getBalance(web3, { address: contractAddr });
10299
const balanceInPht = Web3Wrapper.utils.toPht(balanceInWei);
103-
console.log(`GSNProfileFactory contract has ${balanceInPht} PHT in balance`);
100+
logger(`GSNProfileFactory contract has ${balanceInPht} PHT in balance`);
104101
const newProfileFundingInWei = await Web3Wrapper.contractCall(web3, {
105102
to: contractAddr,
106103
abi: factoryScJSON.abi,
@@ -260,7 +257,7 @@ module.exports.hatchArtistToken = async (web3, {from, contractAddr, artistTokenA
260257
}
261258

262259
const tokens = receipt.events['HatchedArtistTokens'].returnValues['amount'];
263-
console.log(`Hatcher ${from} obtained an estimated amount of ${Web3Wrapper.utils.toPht(tokens).toString()} ArtistTokens ${artistTokenAddr}`);
260+
logger(`Hatcher ${from} obtained an estimated amount of ${Web3Wrapper.utils.toPht(tokens).toString()} ArtistTokens ${artistTokenAddr}`);
264261
return Web3Wrapper.utils.toBN(tokens);
265262
};
266263

@@ -284,7 +281,7 @@ module.exports.claimArtistToken = async (web3, {from, contractAddr, artistTokenA
284281
}
285282

286283
const tokens = receipt.events['ClaimedArtistTokens'].returnValues['amount'];
287-
console.log(`Hatcher ${from} claimed an amount of ${Web3Wrapper.utils.toPht(tokens).toString()} ArtistTokens ${artistTokenAddr}`);
284+
logger(`Hatcher ${from} claimed an amount of ${Web3Wrapper.utils.toPht(tokens).toString()} ArtistTokens ${artistTokenAddr}`);
288285
return Web3Wrapper.utils.toBN(tokens);
289286
};
290287

@@ -309,7 +306,7 @@ module.exports.refundArtistToken = async (web3, {from, contractAddr, artistToken
309306
}
310307

311308
const tokens = receipt.events['RefundedTokens'].returnValues['amount'];
312-
console.log(`Hatcher ${from} get a refund of ${Web3Wrapper.utils.toPht(tokens).toString()} WPHT tokens`);
309+
logger(`Hatcher ${from} get a refund of ${Web3Wrapper.utils.toPht(tokens).toString()} WPHT tokens`);
313310
return Web3Wrapper.utils.toBN(tokens);
314311
};
315312

@@ -333,6 +330,6 @@ module.exports.buyArtistToken = async(web3, {from, contractAddr, artistTokenAddr
333330
}
334331

335332
const tokens = receipt.events['BoughtArtistTokens'].returnValues['amount'];
336-
console.log(`Buyer ${from} purchased ${Web3Wrapper.utils.toPht(tokens).toString()} of ArtistTokens ${artistTokenAddr}`);
333+
logger(`Buyer ${from} purchased ${Web3Wrapper.utils.toPht(tokens).toString()} of ArtistTokens ${artistTokenAddr}`);
337334
return Web3Wrapper.utils.toBN(tokens);
338335
};

0 commit comments

Comments
 (0)