1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-25 11:28:37 +01:00

encode public_keys array for threshold conditions

This commit is contained in:
Scott Sadler 2017-06-23 10:24:23 +02:00
parent 52c3505b32
commit 6fa2b2e7e5
2 changed files with 26 additions and 13 deletions

View File

@ -10,10 +10,18 @@ export default function makeOutput(condition, amount = '1') {
if (typeof amount !== 'string') {
throw new TypeError('`amount` must be of type string')
}
const publicKeys = []
const getPublicKeys = details => {
if (details.type === 'ed25519-sha-256') {
publicKeys.push(details.public_key)
} else if (details.type === 'threshold-sha-256') {
details.subfulfillments.map(getPublicKeys)
}
}
getPublicKeys(condition.details)
return {
'amount': amount,
condition,
'public_keys': condition.details.hasOwnProperty('public_key') ?
[condition.details.public_key] : [],
'amount': amount,
'public_keys': publicKeys,
}
}

View File

@ -21,19 +21,24 @@ test('Threshold condition encoding', t => {
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
const condition = Transaction.makeThresholdCondition(
1, [Transaction.makeEd25519Condition(publicKey, false)])
const output = Transaction.makeOutput(condition)
const target = {
details: {
type: 'threshold-sha-256',
threshold: 1,
subfulfillments: [{
type: 'ed25519-sha-256',
public_key: publicKey,
signature: null,
}]
condition: {
details: {
type: 'threshold-sha-256',
threshold: 1,
subfulfillments: [{
type: 'ed25519-sha-256',
public_key: publicKey,
signature: null,
}]
},
uri: 'ni:///sha-256;VBIfZSoBprUQy-LVNAzaZ2q-eyWbrcPKtBg1PuNXIpQ?fpt=threshold-sha-256&cost=132096&subtypes=ed25519-sha-256',
},
uri: 'ni:///sha-256;VBIfZSoBprUQy-LVNAzaZ2q-eyWbrcPKtBg1PuNXIpQ?fpt=threshold-sha-256&cost=132096&subtypes=ed25519-sha-256'
amount: '1',
public_keys: [publicKey]
}
t.deepEqual(target, condition)
t.deepEqual(target, output)
})