From 886066b1a68ce50ff1d9b263aadb48ff5278848c Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Thu, 6 Jun 2019 12:44:23 +0300 Subject: [PATCH 1/6] fix comment --- logic/transaction.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/logic/transaction.js b/logic/transaction.js index 06267237..ff6acf44 100644 --- a/logic/transaction.js +++ b/logic/transaction.js @@ -22,6 +22,9 @@ var self, modules, __private = {}; * - 5: DApp * - 6: InTransfer * - 7: OutTransfer + * - 8: ChatMessage + * - 9: KVS + * */ __private.types = {}; @@ -1234,4 +1237,4 @@ Transaction.prototype.bindModules = function (__modules) { }; // Export -module.exports = Transaction; \ No newline at end of file +module.exports = Transaction; From 6072b1e5944a0e4052bf3443b6a9473209e985e7 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Thu, 6 Jun 2019 14:43:09 +0300 Subject: [PATCH 2/6] Get data from fuller view so that get?id could return transation assets. --- .../20190601142900_createTrsListFullView.sql | 49 +++++++++++++++++++ sql/transactions.js | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 sql/migrations/20190601142900_createTrsListFullView.sql diff --git a/sql/migrations/20190601142900_createTrsListFullView.sql b/sql/migrations/20190601142900_createTrsListFullView.sql new file mode 100644 index 00000000..f42239b2 --- /dev/null +++ b/sql/migrations/20190601142900_createTrsListFullView.sql @@ -0,0 +1,49 @@ +/* + * create 'trs_list_full' view, normalize addresses, add indexes + */ + +BEGIN; + +DROP VIEW IF EXISTS trs_list_full; + +CREATE VIEW trs_list_full AS + +SELECT t."id" AS "t_id", + b."height" AS "b_height", + t."blockId" AS "t_blockId", + t."type" AS "t_type", + t."timestamp" AS "t_timestamp", + t."senderPublicKey" AS "t_senderPublicKey", + m."publicKey" AS "m_recipientPublicKey", + UPPER(t."senderId") AS "t_senderId", + UPPER(t."recipientId") AS "t_recipientId", + t."amount" AS "t_amount", + t."fee" AS "t_fee", + ENCODE(t."signature", 'hex') AS "t_signature", + ENCODE(t."signSignature", 'hex') AS "t_SignSignature", + t."signatures" AS "t_signatures", + (SELECT height + 1 FROM blocks ORDER BY height DESC LIMIT 1) - b."height" AS "confirmations", + d."username" AS "d_username", + v."votes" AS "v_votes", + ms."min" AS "m_min", + ms."lifetime" AS "m_lifetime", + ms."keysgroup" AS "m_keysgroup", + c."message" AS "c_message", + c."own_message" AS "c_own_message", + c."type" AS "c_type", + st."type" as "st_type", + st."stored_value" as "st_stored_value", + st."stored_key" as "st_stored_key" +FROM trs t + +LEFT JOIN blocks b ON t."blockId" = b."id" +LEFT JOIN mem_accounts m ON t."recipientId" = m."address" +LEFT OUTER JOIN delegates AS d ON d."transactionId" = t."id" +LEFT OUTER JOIN votes AS v ON v."transactionId" = t."id" +LEFT OUTER JOIN signatures AS s ON s."transactionId" = t."id" +LEFT OUTER JOIN multisignatures AS ms ON ms."transactionId" = t."id" +LEFT OUTER JOIN chats AS c ON c."transactionId" = t."id" +LEFT OUTER JOIN states AS st ON st."transactionId" = t."id"; + + +COMMIT; diff --git a/sql/transactions.js b/sql/transactions.js index 435d5702..bfdba3fb 100644 --- a/sql/transactions.js +++ b/sql/transactions.js @@ -44,7 +44,7 @@ var TransactionsSql = { ].filter(Boolean).join(' '); }, - getById: 'SELECT *, ENCODE ("t_senderPublicKey", \'hex\') AS "t_senderPublicKey", ENCODE ("m_recipientPublicKey", \'hex\') AS "m_recipientPublicKey" FROM trs_list WHERE "t_id" = ${id}', + getById: 'SELECT *, ENCODE ("t_senderPublicKey", \'hex\') AS "t_senderPublicKey", ENCODE ("m_recipientPublicKey", \'hex\') AS "m_recipientPublicKey" FROM trs_list_full WHERE "t_id" = ${id}', getVotesById: 'SELECT * FROM votes WHERE "transactionId" = ${id}' }; From cc7559c4953a50b1fb01cfe78f1b48ba63fbaf62 Mon Sep 17 00:00:00 2001 From: zyuhel Date: Thu, 6 Jun 2019 14:56:52 +0300 Subject: [PATCH 3/6] Bump version to 0.5.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 435ae309..f54a1a19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "adamant", - "version": "0.5.1", + "version": "0.5.2", "private": true, "scripts": { "start": "node app.js", From d2e6eb6b44be6a29f8c6a44c5ac830178e0a5cf8 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Sun, 9 Jun 2019 23:26:58 +0300 Subject: [PATCH 4/6] Add returnAsset argument --- modules/transactions.js | 35 +++++++++++++++++++++++++++++++---- sql/transactions.js | 18 +++++++++++++++++- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/modules/transactions.js b/modules/transactions.js index 3b33dae8..eff8aad8 100644 --- a/modules/transactions.js +++ b/modules/transactions.js @@ -202,8 +202,11 @@ __private.list = function (filter, cb) { owner: owner }), params).then(function (rows) { var count = rows.length ? rows[0].count : 0; - - library.db.query(sql.list({ + var sql_method='list'; + if (filter.returnAsset) { + sql_method = 'listFull'; + } + library.db.query(sql[sql_method]({ where: where, owner: owner, sortField: orderBy.sortField, @@ -253,6 +256,27 @@ __private.getById = function (id, cb) { }); }; +/** + * Gets transaction by id from `trs_list_full` view. + * @private + * @param {string} id + * @param {function} cb - Callback function. + * @returns {setImmediateCallback} error | data: {transaction} + */ +__private.getByIdFullAsset = function (id, cb) { + library.db.query(sql.getByIdFull, {id: id}).then(function (rows) { + if (!rows.length) { + return setImmediate(cb, 'Transaction not found: ' + id); + } + + var transacton = library.logic.transaction.dbRead(rows[0]); + + return setImmediate(cb, null, transacton); + }).catch(function (err) { + library.logger.error(err.stack); + return setImmediate(cb, 'Transactions#getById error'); + }); +}; /** * Gets votes by transaction id from `votes` table. * @private @@ -666,8 +690,11 @@ Transactions.prototype.shared = { if (err) { return setImmediate(cb, err[0].message); } - - __private.getById(req.body.id, function (err, transaction) { + var method='getById'; + if (req.body.returnAsset) { + method = 'getByIdFullAsset'; + } + __private[method](req.body.id, function (err, transaction) { if (!transaction || err) { return setImmediate(cb, 'Transaction not found'); } diff --git a/sql/transactions.js b/sql/transactions.js index bfdba3fb..54168f8e 100644 --- a/sql/transactions.js +++ b/sql/transactions.js @@ -43,8 +43,24 @@ var TransactionsSql = { 'LIMIT ${limit} OFFSET ${offset}' ].filter(Boolean).join(' '); }, + listFull: function (params) { + return [ + 'SELECT "t_id", "b_height", "t_blockId", "t_type", "t_timestamp", "t_senderId", "t_recipientId",', + '"t_amount", "t_fee", "t_signature", "t_SignSignature", "t_signatures", "confirmations",', + 'ENCODE ("t_senderPublicKey", \'hex\') AS "t_senderPublicKey", ENCODE ("m_recipientPublicKey", \'hex\') AS "m_recipientPublicKey",', + '"d_username", "v_votes", "m_min", "m_lifetime", "m_keysgroup", "c_message", "c_own_message", "c_type", "st_type", "st_stored_value", "st_stored_key" ' + 'FROM trs_list_full', + (params.where.length || params.owner ? 'WHERE' : ''), + (params.where.length ? '(' + params.where.join(' ') + ')' : ''), + // FIXME: Backward compatibility, should be removed after transitional period + (params.where.length && params.owner ? ' AND ' + params.owner : params.owner), + (params.sortField ? 'ORDER BY ' + [params.sortField, params.sortMethod].join(' ') : ''), + 'LIMIT ${limit} OFFSET ${offset}' + ].filter(Boolean).join(' '); + }, - getById: 'SELECT *, ENCODE ("t_senderPublicKey", \'hex\') AS "t_senderPublicKey", ENCODE ("m_recipientPublicKey", \'hex\') AS "m_recipientPublicKey" FROM trs_list_full WHERE "t_id" = ${id}', + getById: 'SELECT *, ENCODE ("t_senderPublicKey", \'hex\') AS "t_senderPublicKey", ENCODE ("m_recipientPublicKey", \'hex\') AS "m_recipientPublicKey" FROM trs_list WHERE "t_id" = ${id}', + getByIdFull: 'SELECT *, ENCODE ("t_senderPublicKey", \'hex\') AS "t_senderPublicKey", ENCODE ("m_recipientPublicKey", \'hex\') AS "m_recipientPublicKey" FROM trs_list_full WHERE "t_id" = ${id}', getVotesById: 'SELECT * FROM votes WHERE "transactionId" = ${id}' }; From 2d44a5641e9296304ba262af0631905628e67fc5 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Mon, 10 Jun 2019 12:51:59 +0300 Subject: [PATCH 5/6] Fix type --- sql/transactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/transactions.js b/sql/transactions.js index 54168f8e..edad2934 100644 --- a/sql/transactions.js +++ b/sql/transactions.js @@ -48,7 +48,7 @@ var TransactionsSql = { 'SELECT "t_id", "b_height", "t_blockId", "t_type", "t_timestamp", "t_senderId", "t_recipientId",', '"t_amount", "t_fee", "t_signature", "t_SignSignature", "t_signatures", "confirmations",', 'ENCODE ("t_senderPublicKey", \'hex\') AS "t_senderPublicKey", ENCODE ("m_recipientPublicKey", \'hex\') AS "m_recipientPublicKey",', - '"d_username", "v_votes", "m_min", "m_lifetime", "m_keysgroup", "c_message", "c_own_message", "c_type", "st_type", "st_stored_value", "st_stored_key" ' + '"d_username", "v_votes", "m_min", "m_lifetime", "m_keysgroup", "c_message", "c_own_message", "c_type", "st_type", "st_stored_value", "st_stored_key" ', 'FROM trs_list_full', (params.where.length || params.owner ? 'WHERE' : ''), (params.where.length ? '(' + params.where.join(' ') + ')' : ''), From 18b3a8c926a600eacf660c0f048ac1fefd3530bc Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Mon, 10 Jun 2019 13:02:14 +0300 Subject: [PATCH 6/6] Add returnAsset parameter range --- modules/transactions.js | 1 + schema/transactions.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/modules/transactions.js b/modules/transactions.js index eff8aad8..2eca2444 100644 --- a/modules/transactions.js +++ b/modules/transactions.js @@ -101,6 +101,7 @@ __private.list = function (filter, cb) { limit: null, offset: null, orderBy: null, + returnAsset: null, // FIXME: Backward compatibility, should be removed after transitional period ownerAddress: null, ownerPublicKey: null diff --git a/schema/transactions.js b/schema/transactions.js index 9226eeac..860ead1e 100644 --- a/schema/transactions.js +++ b/schema/transactions.js @@ -165,6 +165,11 @@ module.exports = { offset: { type: 'integer', minimum: 0 + }, + returnAsset: { + type: 'integer', + minimum: 0, + maximum: 1 } } }, @@ -177,6 +182,11 @@ module.exports = { format: 'id', minLength: 1, maxLength: 20 + }, + returnAsset: { + type: 'integer', + minimum: 0, + maximum: 1 } }, required: ['id']