Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #439 from jimni1222/kctFD
Browse files Browse the repository at this point in the history
Supported FD in caver.kct
  • Loading branch information
jimni1222 authored Apr 6, 2021
2 parents bdf07cc + 91e2490 commit a671309
Show file tree
Hide file tree
Showing 8 changed files with 1,091 additions and 284 deletions.
21 changes: 15 additions & 6 deletions packages/caver-kct/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with the caver-js. If not, see <http://www.gnu.org/licenses/>.
*/

const _ = require('lodash')
const BaseKIP7 = require('./kip7')
const BaseKIP17 = require('./kip17')
const KIP37 = require('./kip37')
Expand Down Expand Up @@ -71,23 +72,27 @@ class KCT {
* The KIP7 instance deployed and returned through this function uses the keyringContainer instead of accounts.
* @method deploy
* @param {Object} tokenInfo The object that defines the name, symbol, decimals, and initialSupply of the token to deploy.
* @param {String} deployer The address of the account to deploy the KIP-7 token contract.
* @param {Object|String} sendOptions The address of the account to deploy the KIP-7 token contract or an object holding parameters that are required for sending a transaction.
* @param {IWallet} wallet The wallet instance to sign and send a transaction.
* @return {object}
*/
static deploy(tokenInfo, deployer, wallet) {
static deploy(tokenInfo, sendOptions, wallet) {
validateDeployParameterForKIP7(tokenInfo)

const { name, symbol, decimals, initialSupply } = tokenInfo
const kip7 = new KIP7()
if (wallet !== undefined) kip7.setWallet(wallet)

// If sendOptions is string type, sendOptions means deployer's address
if (_.isString(sendOptions)) sendOptions = { from: sendOptions, gas: 4000000, value: 0 }
sendOptions.gas = sendOptions.gas !== undefined ? sendOptions.gas : 4000000

return kip7
.deploy({
data: kip7ByteCode,
arguments: [name, symbol, decimals, initialSupply],
})
.send({ from: deployer, gas: 4000000, value: 0 })
.send(sendOptions)
}

/**
Expand Down Expand Up @@ -132,23 +137,27 @@ class KCT {
* The KIP17 instance deployed and returned through this function uses the keyringContainer instead of accounts.
* @method deploy
* @param {Object} tokenInfo The object that defines the name and symbol of the token to deploy.
* @param {String} deployer The address of the account to deploy the KIP-17 token contract.
* @param {Object|String} sendOptions The address of the account to deploy the KIP-17 token contract or an object holding parameters that are required for sending a transaction.
* @param {IWallet} wallet The wallet instance to sign and send a transaction.
* @return {object}
*/
static deploy(tokenInfo, deployer, wallet) {
static deploy(tokenInfo, sendOptions, wallet) {
validateDeployParameterForKIP17(tokenInfo)

const { name, symbol } = tokenInfo
const kip17 = new KIP17()
if (wallet !== undefined) kip17.setWallet(wallet)

// If sendOptions is string type, sendOptions means deployer's address
if (_.isString(sendOptions)) sendOptions = { from: sendOptions, gas: 6600000, value: 0 }
sendOptions.gas = sendOptions.gas !== undefined ? sendOptions.gas : 6600000

return kip17
.deploy({
data: kip17ByteCode,
arguments: [name, symbol],
})
.send({ from: deployer, gas: 6600000, value: 0 })
.send(sendOptions)
}

/**
Expand Down
16 changes: 11 additions & 5 deletions packages/caver-kct/src/kctHelper.js

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

37 changes: 21 additions & 16 deletions packages/caver-kct/src/kip17.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ class KIP17 extends Contract {
*
* @method deploy
* @param {Object} tokenInfo The object that defines the name and symbol of the token to deploy.
* @param {String} deployer The address of the account to deploy the KIP-17 token contract.
* @param {Object|String} sendOptions The address of the account to deploy the KIP-17 token contract or an object holding parameters that are required for sending a transaction.
* @return {Object}
*/
static deploy(tokenInfo, deployer) {
static deploy(tokenInfo, sendOptions) {
validateDeployParameterForKIP17(tokenInfo)

const { name, symbol } = tokenInfo
const kip17 = new KIP17()

// If sendOptions is string type, sendOptions means deployer's address
if (_.isString(sendOptions)) sendOptions = { from: sendOptions, gas: 6600000, value: 0 }
sendOptions.gas = sendOptions.gas !== undefined ? sendOptions.gas : 6600000

return kip17
.deploy({
data: kip17ByteCode,
arguments: [name, symbol],
})
.send({ from: deployer, gas: 6600000, value: 0 })
.send(sendOptions)
}

/**
Expand Down Expand Up @@ -316,7 +320,7 @@ class KIP17 extends Contract {
*/
async approve(to, tokenId, sendParam = {}) {
const executableObj = this.methods.approve(to, formatParamForUint256(tokenId))
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -334,7 +338,7 @@ class KIP17 extends Contract {
*/
async setApprovalForAll(to, approved, sendParam = {}) {
const executableObj = this.methods.setApprovalForAll(to, approved)
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -352,7 +356,7 @@ class KIP17 extends Contract {
*/
async transferFrom(from, to, tokenId, sendParam = {}) {
const executableObj = this.methods.transferFrom(from, to, formatParamForUint256(tokenId))
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand Down Expand Up @@ -387,7 +391,7 @@ class KIP17 extends Contract {
? this.methods.safeTransferFrom(from, to, formatParamForUint256(tokenId), data)
: this.methods.safeTransferFrom(from, to, formatParamForUint256(tokenId))

sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -404,7 +408,7 @@ class KIP17 extends Contract {
*/
async addMinter(account, sendParam = {}) {
const executableObj = this.methods.addMinter(account)
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -420,7 +424,7 @@ class KIP17 extends Contract {
*/
async renounceMinter(sendParam = {}) {
const executableObj = this.methods.renounceMinter()
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -437,7 +441,7 @@ class KIP17 extends Contract {
*/
async mint(to, tokenId, sendParam = {}) {
const executableObj = this.methods.mint(to, formatParamForUint256(tokenId))
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -455,7 +459,7 @@ class KIP17 extends Contract {
*/
async mintWithTokenURI(to, tokenId, tokenURI, sendParam = {}) {
const executableObj = this.methods.mintWithTokenURI(to, formatParamForUint256(tokenId), tokenURI)
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -471,7 +475,7 @@ class KIP17 extends Contract {
*/
async burn(tokenId, sendParam = {}) {
const executableObj = this.methods.burn(formatParamForUint256(tokenId))
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -487,7 +491,7 @@ class KIP17 extends Contract {
*/
async pause(sendParam = {}) {
const executableObj = this.methods.pause()
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -505,7 +509,7 @@ class KIP17 extends Contract {
*/
async unpause(sendParam = {}) {
const executableObj = this.methods.unpause()
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -522,7 +526,7 @@ class KIP17 extends Contract {
*/
async addPauser(account, sendParam = {}) {
const executableObj = this.methods.addPauser(account)
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
Expand All @@ -538,10 +542,11 @@ class KIP17 extends Contract {
*/
async renouncePauser(sendParam = {}) {
const executableObj = this.methods.renouncePauser()
sendParam = await determineSendParams(executableObj, sendParam, this.options.from)
sendParam = await determineSendParams(executableObj, sendParam, this.options)

return executableObj.send(sendParam)
}
}

KIP17.byteCode = kip17ByteCode
module.exports = KIP17
Loading

0 comments on commit a671309

Please sign in to comment.