Skip to content

Commit

Permalink
fix: 🐛 Update @ddn/node-sdk export messages
Browse files Browse the repository at this point in the history
  • Loading branch information
limsbase committed Jul 29, 2020
1 parent 1d320b8 commit 96762c7
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 39 deletions.
4 changes: 2 additions & 2 deletions docs/api/aob-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ curl -X GET -H "Content-Type: application/json" 'http://localhost:8001/api/aob/a
var currency = 'IssuerName.CNY'
// 本次发行量=真实数量(100)*10**精度(3),所有发行量之和需 <= 上限*精度
var amount = '100000'
var trs = DdnJS.aob.createIssue(currency, amount, secret, secondSecret)
var trs = await DdnJS.aob.createIssue(currency, amount, secret, secondSecret)
console.log(JSON.stringify(trs))
{"type":13,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19475744,"asset":{"aobIssue":{"currency":"IssuerName.CNY","amount":"100000"}},"signature":"32b01a18eca2b0dc7e2ce77ba4e758eaae2532f60844760a762cc20918e7439ac6ca585b921db6ede833ed0bf1c62e30cec545a928abafe0b679183a6ad02202","signSignature":"4fc290d7d7d788e9112a56233df0fe796cba39be3efa0cebf00cbc7e5bc5fd1369fad49e5698d967845b5c02e427926049cab25845d4d385e4a395791906f909"}

curl -H "Content-Type: application/json" -H "nethash:0ab796cd" -H "version:''" -k -X POST -d '{"transaction":{"type":13,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19475744,"asset":{"aobIssue":{"currency":"IssuerName.CNY","amount":"100000"}},"signature":"32b01a18eca2b0dc7e2ce77ba4e758eaae2532f60844760a762cc20918e7439ac6ca585b921db6ede833ed0bf1c62e30cec545a928abafe0b679183a6ad02202","signSignature":"4fc290d7d7d788e9112a56233df0fe796cba39be3efa0cebf00cbc7e5bc5fd1369fad49e5698d967845b5c02e427926049cab25845d4d385e4a395791906f909"}}' 'http://localhost:8001/peer/transactions' && echo
curl -H "Content-Type: application/json" -H "nethash:gar0fktt" -H "version:''" -k -X POST -d '{"transaction":{"type":64,"nethash":"gar0fktt","amount":"0","fee":"10000000","recipientId":null,"senderPublicKey":"1e18845d5fbbdf0a6820610e042dcb9a250205964b8075a395453b4a1d1ed10c","timestamp":84812020,"message":null,"asset":{"aobIssue":{"currency":"rcpDa.TRCP","amount":"10000"}},"signature":"5d0d19f2c40714715bc0f868d907489c07527af618441c6c76314bbad5b9487ac3bc09451d11f3874256ef10a9115dabab1b2f53451619653350c94f28015e07"}}' 'http://192.160.120.200:8001/peer/transactions' && echo
```

JSON返回示例:
Expand Down
13 changes: 12 additions & 1 deletion examples/fun-tests/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,22 @@ module.exports = {

// Fees for transacton
fees: {
// base
send: '10000000',
vote: '100000000',
vote: '10000000',
secondSignature: '500000000',
delegate: '10000000000',
multiSignature: '500000000',

// aob
aob_issuer: '100',
aob_asset: '500',
aob_flag: '0.1',
aob_acl: '0.1',
aob_issue: '0.1',
aob_transfer: '0',

// dapp
dappRegistration: '2500000000',
dappWithdrawal: '10000000',
dappDeposit: '10000000',
Expand Down
13 changes: 12 additions & 1 deletion packages/asset-aob/src/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import DdnUtils from '@ddn/utils'
import DdnCrypto from '@ddn/crypto'

class Transfer extends Asset.Base {
// eslint-disable-next-line no-useless-constructor
// constructor (context, transactionConfig) {
// super(context, transactionConfig)
// // console.log()
// }

async propsMapping () {
return [
{
Expand All @@ -28,7 +34,12 @@ class Transfer extends Asset.Base {

return buffer
}


async calculateFee () {
console.log('this.constants[this.config.net].fees.aob_transfer', this.constants[this.config.net].fees.aob_transfer)
return DdnUtils.bignum.multiply(this.constants[this.config.net].fees.aob_transfer, this.constants.fixedPoint)
}

async create (data, trs) {
trs.recipientId = data.recipientId
trs.amount = '0'
Expand Down
3 changes: 2 additions & 1 deletion packages/asset-base/src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class AssetBase {
* @param {*} sender
*/
async calculateFee () {
return DdnUtils.bignum.multiply(0.1, 100000000) // fixme: 这里应该可以定制 2020.5.31
console.log('base.js...................')
// return DdnUtils.bignum.multiply(0.0002, 100) // fixme: 这里应该可以定制 2020.5.31
}

/**
Expand Down
17 changes: 2 additions & 15 deletions packages/node-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
"dist"
],
"scripts": {
"test": "mocha test",
"build": "yarn build:dev & yarn build:prod",
"build:dev": "browserify index.browser.js > ./dist/ddn.browserify.js",
"build:prod": "browserify index.browser.js -p tinyify > ./dist/ddn.browserify.min.js"
"test": "mocha test"
},
"keywords": [
"ddn",
Expand Down Expand Up @@ -46,18 +43,8 @@
"through2": "^2.0.3",
"tweetnacl": "^1.0.2"
},
"npmFileMap": [
{
"basePath": "/dist/",
"files": [
"*.js"
]
}
],
"devDependencies": {
"browserify": "^13.1.0",
"rollup-plugin-replace": "^2.2.0",
"tinyify": "^2.5.2"
"rollup-plugin-replace": "^2.2.0"
},
"gitHead": "26a701eeebd9d9f8c72a73cb18080170f6fd4fde"
}
11 changes: 11 additions & 0 deletions packages/node-sdk/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,22 @@ export default {

// Fees for transacton
fees: {
// base
send: '10000000',
vote: '10000000',
secondSignature: '500000000',
delegate: '10000000000',
multiSignature: '500000000',

// aob
aob_issuer: '100',
aob_asset: '500',
aob_flag: '0.1',
aob_acl: '0.1',
aob_issue: '0.1',
aob_transfer: '0',

// dapp
dappRegistration: '2500000000',
dappWithdrawal: '10000000',
dappDeposit: '10000000',
Expand Down
5 changes: 4 additions & 1 deletion packages/node-sdk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import exchange from './transactions/exchange'
import coupon from './transactions/coupon'
import assetPlugin from './transactions/asset-plugin'

export * from './config'
import { config, constants } from './config'

export default {
config,
constants,

utils: {
slots,
format
Expand Down
28 changes: 13 additions & 15 deletions packages/node-sdk/src/transactions/aob.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function createTransaction (
transaction.sign_signature = await DdnCrypto.secondSign(transaction, secondKeys)
}

// transaction.id = await DdnCrypto.getId(transaction)
transaction.id = await DdnCrypto.getId(transaction)

return transaction
}
Expand All @@ -52,7 +52,7 @@ export default {
desc
}
}
const fee = bignum.multiply(100, constants.fixedPoint)
const fee = bignum.multiply(constants.net.fees.aob_issuer, constants.fixedPoint)
const trs = await createTransaction(
asset,
fee,
Expand Down Expand Up @@ -91,7 +91,7 @@ export default {
}
}
// var fee = (500 + (Math.floor(bytes.length / 200) + 1) * 0.1) * constants.fixedPoint
const fee = bignum.multiply(500, constants.fixedPoint)
const fee = bignum.multiply(constants.net.fees.aob_asset, constants.fixedPoint)
return await createTransaction(
asset,
fee,
Expand All @@ -111,7 +111,7 @@ export default {
flag
}
}
const fee = bignum.multiply(0.1, constants.fixedPoint)
const fee = bignum.multiply(constants.net.fees.aob_flag, constants.fixedPoint)
return await createTransaction(
asset,
fee,
Expand All @@ -132,7 +132,7 @@ export default {
list
}
}
const fee = bignum.multiply(0.1, constants.fixedPoint)
const fee = bignum.multiply(constants.net.fees.aob_acl, constants.fixedPoint)
return await createTransaction(
asset,
fee,
Expand All @@ -151,7 +151,10 @@ export default {
amount: `${amount}`
}
}
const fee = bignum.multiply(0.1, constants.fixedPoint)
const fee = bignum.multiply(constants.net.fees.aob_issue, constants.fixedPoint)

console.log('createIssue', fee, `${fee}`)

const trs = await createTransaction(
asset,
fee,
Expand All @@ -165,21 +168,16 @@ export default {
return trs
},

async createTransfer (
currency,
amount,
recipientId,
message,
secret,
secondSecret
) {
async createTransfer (currency, amount, recipientId, message, secret, secondSecret) {
const asset = {
aobTransfer: {
currency,
amount: `${amount}`
}
}
const fee = bignum.multiply(0.1, constants.fixedPoint)
const fee = bignum.multiply(constants.net.fees.aob_transfer, constants.fixedPoint)
console.log('createTransfer', fee, `${fee}`)

return await createTransaction(
asset,
fee,
Expand Down
5 changes: 4 additions & 1 deletion packages/node-sdk/test/unit/2.aob.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ describe('AOB Test', () => {
}

// const transaction = await createPluginAsset(65, obj, IssuerAccount1.password);
const transaction = await createPluginAsset(DdnUtils.assetTypes.AOB_TRANSFER, obj, IssuerAccount1.password)
// const transaction = await createPluginAsset(DdnUtils.assetTypes.AOB_TRANSFER, obj, IssuerAccount1.password)
const transaction = await DdnJS.aob.createTransfer(currency, '1', IssuerAccount2.address, 'test', IssuerAccount1.password)

debug('transfer ok', transaction)

node.peer.post('/transactions')
.set('Accept', 'application/json')
Expand Down
4 changes: 2 additions & 2 deletions packages/peer/src/kernal/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ class Transaction {

if (trs.id && trs.id !== txId) {
// FIXME: 这里没有要求从Asset插件端传ID,不然会出错,请确认
this.logger.error('trs.id', trs.id)
this.logger.error('txId', txId)
this.logger.debug('trs.id', trs.id)
this.logger.debug('txId', txId)
throw new Error('Incorrect transaction id 2')
} else {
trs.id = txId
Expand Down

0 comments on commit 96762c7

Please sign in to comment.