Skip to content

Commit 444c853

Browse files
author
coranos
committed
fixed #5
1 parent eb37b6e commit 444c853

File tree

7 files changed

+26
-35
lines changed

7 files changed

+26
-35
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"itest": "./node_modules/mocha/bin/mocha --recursive -t 100000 test/integration"
2525
},
2626
"dependencies": {
27+
"@bananocoin/banano-ipfs": "^1.0.1",
2728
"@bananocoin/bananojs": "^2.4.15",
2829
"abort-controller": "^3.0.0",
2930
"await-semaphore": "^0.1.3",

scripts/actions/get-nft-template-owner.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ const getNftAssetsOwners = async (context, req, res) => {
114114
}
115115

116116
/* istanbul ignore if */
117-
if (ipfsResp.representative === undefined) {
118-
throw Error('ipfsResp.representative is required');
117+
if (ipfsResp.representative_account === undefined) {
118+
throw Error('ipfsResp.representative_account is required');
119119
}
120120

121121
const histBody = {
@@ -152,7 +152,7 @@ const getNftAssetsOwners = async (context, req, res) => {
152152
} else {
153153
resp.success = true;
154154
resp.asset_owners = [];
155-
const representativeAccount = await bananojs.getBananoAccount(representative);
155+
const representativeAccount = ipfsResp.representative_account;
156156
loggingUtil.log(ACTION, 'representativeAccount', representativeAccount);
157157
let templateAssetCounter = 0;
158158
for (let ix = 0; ix < histResponseJson.history.length; ix++) {

scripts/ipfs-util.js

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
// libraries
3+
const bananoIpfs = require('@bananocoin/banano-ipfs');
34
const bs58 = require('bs58');
45
const AbortController = require('abort-controller');
56

@@ -677,31 +678,14 @@ const addRep = async (bananojs, json, inFieldNmPrefix, outFieldNmPrefix, errors,
677678
if (value === undefined) {
678679
throw Error(`'${key}' not a key in ${Object.keys(json)}`);
679680
}
680-
if (!regExp.test(value)) {
681-
errors.push(`${key}:'${value}' not Qm+base58`);
681+
const representativeAccountFieldNm = `${outFieldNmPrefix}representative_account`;
682+
try {
683+
const representative = bananoIpfs.ifpsCidToAccount(value);
684+
json[representativeAccountFieldNm] = representative;
685+
return success;
686+
} catch (error) {
687+
errors.push(`${key}:'${value}' error '${error.message}'`);
682688
return false;
683-
} else {
684-
const bytes = bs58.decode(value);
685-
686-
const hexFieldNm = `${outFieldNmPrefix}ipfs_cid_hex`;
687-
const hexBase58FieldNm = `${outFieldNmPrefix}ipfs_cid_hex_base58`;
688-
689-
const hexValue = bytes.toString('hex');
690-
json[hexFieldNm] = hexValue;
691-
json[hexBase58FieldNm] = bs58.encode(Buffer.from(bytes));
692-
693-
const regExp = new RegExp('^1220[0123456789abcdefABCDEF]{64}$');
694-
if (!regExp.test(hexValue)) {
695-
// check https://github.com/multiformats/js-cid
696-
errors.push(`${hexFieldNm}:'${hexValue}' not 64 hex characters after prefix 1220, ${hexValue.length}`);
697-
return false;
698-
} else {
699-
const representativeFieldNm = `${outFieldNmPrefix}representative`;
700-
const representativeAccountFieldNm = `${outFieldNmPrefix}representative_account`;
701-
json[representativeFieldNm] = hexValue.substring(4);
702-
json[representativeAccountFieldNm] = await bananojs.getBananoAccount(json[representativeFieldNm]);
703-
return success;
704-
}
705689
}
706690
};
707691

static-html/actions/navigation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ window.hideOwnerAssetCheckWrappers = () => {
152152
window.showGalleryWrappers = () => {
153153
hide('navigationWrapper');
154154
show('galleryWrapper');
155-
}
155+
};
156156

157157
window.hideGalleryWrappers = () => {
158158
show('navigationWrapper');
159159
hide('galleryWrapper');
160-
}
160+
};
161161

162162
export {addNavigation};

test/unit/get-nft-info-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ describe(actionUtil.ACTION, () => {
6262
const expectedResponse = {
6363
content_type: 'application/json',
6464
ipfs_cid: goodIpfsCid,
65-
representative: '1d2c906def1e5e04841de91c8b65e0f37c30a3d45c6a2c454fd332d2906f8d57',
6665
representative_account: 'ban_19bek3pyy9ky1k43utawjfky3wuw84jxaq5c7j4nznsktca8z5cqrfg8egjn',
6766
json: {
6867
command: 'nft_template',

test/unit/get-nft-template-owner-test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ describe(actionUtil.ACTION, () => {
787787
'unsupported version:\'\' supported versions:["0.0.1"]',
788788
'max_supply:\'\' not an integer',
789789
'transferable:\'\' not a boolean',
790-
'art_data_ipfs_cid:\'\' not Qm+base58',
790+
'art_data_ipfs_cid:\'\' error \'ipfs_cid:\'\' not valid v0 CID (Qm+base58)\'',
791791
'previous:\'\' not 64 hex characters',
792792
],
793793
ipfs_cid: badJsonIpfsCid,
@@ -846,7 +846,7 @@ describe(actionUtil.ACTION, () => {
846846
const expectedResponse = {
847847
'content_type': 'application/json',
848848
'errors': [
849-
'art_data_ipfs_cid:\'Qm#\' not Qm+base58',
849+
'art_data_ipfs_cid:\'Qm#\' error \'ipfs_cid:\'Qm#\' not valid v0 CID (Qm+base58)\'',
850850
'previous:\'AB\' not 64 hex characters',
851851
],
852852
'ipfs_cid': badJsonBase58Cid,
@@ -877,15 +877,13 @@ describe(actionUtil.ACTION, () => {
877877
const expectedResponse = {
878878
'content_type': 'application/json',
879879
'errors': [
880-
'art_ipfs_cid_hex:\'500080c4b27277b22c373e4f0dbbc86091707c6cc1745a1b3efcf66664bbde9ceb\' not 64 hex characters after prefix 1220, 66',
880+
'art_data_ipfs_cid:\'QmQJXwo7Ee1cgP2QVRMQGrgz29knQrUMfciq2wQWAvdzz\' error \'ipfsCidHex:\'500080c4b27277b22c373e4f0dbbc86091707c6cc1745a1b3efcf66664bbde9ceb\' not 64 hex chars after prefix 1220, 66\'',
881881
'previous:\'AB\' not 64 hex characters',
882882
],
883883
'ipfs_cid': badJsonBase58ShortCid,
884884
'json': {
885885
'command': 'nft_template',
886886
'art_data_ipfs_cid': 'QmQJXwo7Ee1cgP2QVRMQGrgz29knQrUMfciq2wQWAvdzz',
887-
'art_ipfs_cid_hex': '500080c4b27277b22c373e4f0dbbc86091707c6cc1745a1b3efcf66664bbde9ceb',
888-
'art_ipfs_cid_hex_base58': 'QmQJXwo7Ee1cgP2QVRMQGrgz29knQrUMfciq2wQWAvdzz',
889887
'issuer': '',
890888
'max_supply': '1',
891889
'previous': 'AB',

0 commit comments

Comments
 (0)