Comparing version 1.1.0 to 1.2.0
@@ -1,7 +0,5 @@ | ||
const BN = require('bn.js'); | ||
const {blockIndexByteLen} = require('./constants'); | ||
const {blockIndexOffset} = require('./constants'); | ||
const componentsFromBuffer = require('./components_from_buffer'); | ||
const {decBase} = require('./constants'); | ||
const decodeFromBuffer = require('./decode_from_buffer'); | ||
const {endian} = require('./constants'); | ||
@@ -11,2 +9,3 @@ const {heightByteLen} = require('./constants'); | ||
const {outputIndexByteLen} = require('./constants'); | ||
const rawChanId = require('./raw_chan_id'); | ||
@@ -19,3 +18,4 @@ const heightBytesUsed = heightByteLen - heightByteOffset; | ||
{ | ||
number: <Channel Id Number Format String> | ||
[id]: <Channel Id Hex String> | ||
[number]: <Channel Id Number Format String> | ||
} | ||
@@ -33,4 +33,4 @@ | ||
*/ | ||
module.exports = ({number}) => { | ||
if (!number) { | ||
module.exports = ({id, number}) => { | ||
if (!id && !number) { | ||
throw new Error('ExpectedShortChannelIdToDecode'); | ||
@@ -41,6 +41,10 @@ } | ||
if (!!id && Buffer.from(id, 'hex').length !== idLen) { | ||
throw new Error('UnexpectedLengthOfShortChannelId'); | ||
} | ||
try { | ||
const rawId = new BN(number, decBase).toArrayLike(Buffer, endian, idLen); | ||
const channelId = !id ? rawChanId({number}).id : id; | ||
const channel = decodeFromBuffer({id: rawId}); | ||
const channel = componentsFromBuffer({id: Buffer.from(channelId, 'hex')}); | ||
@@ -47,0 +51,0 @@ return { |
@@ -31,3 +31,3 @@ { | ||
}, | ||
"version": "1.1.0" | ||
"version": "1.2.0" | ||
} |
@@ -16,2 +16,11 @@ const {test} = require('tap'); | ||
{ | ||
args: {id: '15fbe70000260000'}, | ||
description: 'Standard testnet channel id', | ||
expected: { | ||
block_height: 1440743, | ||
block_index: 38, | ||
output_index: 0, | ||
}, | ||
}, | ||
{ | ||
args: {number: '590587277833404417'}, | ||
@@ -25,2 +34,11 @@ description: 'Standard bitcoin channel id', | ||
}, | ||
{ | ||
args: {id: '0832300008200001'}, | ||
description: 'Standard bitcoin channel id', | ||
expected: { | ||
block_height: 537136, | ||
block_index: 2080, | ||
output_index: 1, | ||
}, | ||
}, | ||
]; | ||
@@ -27,0 +45,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9277
238