Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Add optional data field with transaction - Closes #26 #470

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
82a06c4
create setup for transactions unit tests
MaciejBaj Mar 6, 2017
ce63b2e
Merging @MaciejBajs 'origin/456-transactions-and-blocks-test' to use …
SargeKhan Mar 11, 2017
85024a9
skipped incomplete unit tests of transcations
SargeKhan Mar 11, 2017
98b8bb0
Added data column to trs table
SargeKhan Mar 11, 2017
a23a36f
incorporate data field in logic/transaction
SargeKhan Mar 11, 2017
0fdfd6e
updated /module/trs to handle data field
SargeKhan Mar 11, 2017
1345fd6
updated transaction schema for data field
SargeKhan Mar 11, 2017
5b8b618
added test case for a possible bug in getbytes
SargeKhan Mar 11, 2017
5e5dfdc
updated trs_view to incorporate data field
SargeKhan Mar 11, 2017
c70237b
included data field to cal. getByte
SargeKhan Mar 11, 2017
1a04585
removed adding bytes when data field not present
SargeKhan Mar 12, 2017
4db440d
updated transaction test cases
SargeKhan Mar 12, 2017
c522841
reverted change in getByte of transaction
SargeKhan Mar 12, 2017
e79aa5a
Merge branch '26-add_data_field_with_transaction' of github.com:Sarge…
SargeKhan Mar 12, 2017
43b9f07
Added test cases for data in unit/transaction
SargeKhan Mar 12, 2017
fb5d94e
Merge branch 'development' into 26-add_data_field_with_transaction
karmacoma Mar 14, 2017
1bc5a5c
replaced jslint with eslint
SargeKhan Mar 19, 2017
d37281b
added some test cases for /logic/transaction
SargeKhan Mar 19, 2017
9c95c3c
changed data type to bytea
SargeKhan Mar 19, 2017
ec45c98
added api level test cases
SargeKhan Mar 19, 2017
b696393
removed extraneous logs
SargeKhan Mar 19, 2017
472f3b9
corrected spellings
SargeKhan Apr 9, 2017
ee7ade8
Merge branch '26-add_data_field_with_transaction' of github.com:Sarge…
SargeKhan Apr 9, 2017
a32aeaa
updated getByte for data field
SargeKhan Apr 9, 2017
afed1d5
added fee for optional data field
SargeKhan May 2, 2017
1b36a59
merged with upstream
SargeKhan May 2, 2017
7c8316f
fixed calculateFee function spelling
SargeKhan May 2, 2017
62e54e9
added unit tests for fee calculation
SargeKhan May 2, 2017
2a716cf
Revert "merged with upstream"
SargeKhan May 2, 2017
119cc68
resolved few failing tests, fixed formatting
SargeKhan May 3, 2017
2c05126
resolved few failing tests
SargeKhan May 4, 2017
f71bcb4
updated calculateFee to use bignum
SargeKhan May 16, 2017
7933a81
added a few tests
SargeKhan Jun 8, 2017
8c21607
adding test cases for the rest of transaction module
SargeKhan Jun 9, 2017
a23cbdc
added test cases for logic/transaction
SargeKhan Jun 11, 2017
b0886b2
added test cases for logic/transaction
SargeKhan Jun 16, 2017
ba227cd
temporary commit
SargeKhan Jun 17, 2017
1703cb1
added tests for transaction, setup structure for vote
SargeKhan Jun 18, 2017
edddc29
some tests for vote trs, refactored moduleInits
SargeKhan Jun 19, 2017
b9593cc
merged with development
SargeKhan Jun 20, 2017
403e3b7
added test cases for votes trs
SargeKhan Jun 20, 2017
9f500f1
added tests for transfer trs
SargeKhan Jun 21, 2017
4356e5d
Merge branch 'development' into 26-add_data_field_with_transaction
SargeKhan Jun 22, 2017
ee400c4
added tests for multisignatures and second signature
SargeKhan Jun 22, 2017
f0a52fc
cleaned tests
SargeKhan Jun 25, 2017
54791da
removed unused variables, better test statments
SargeKhan Jun 26, 2017
918ef84
refactored to subtract amount from account and return error on error …
SargeKhan Jul 3, 2017
56fb6a1
removed some unwanted tests
SargeKhan Jul 3, 2017
e7b369b
Merge remote-tracking branch 'upstream/development' into 26-add_data_…
SargeKhan Jul 3, 2017
6149b81
resolved merge issues, updated git submodule to read 1.0.0 branch
SargeKhan Jul 3, 2017
c65e3c3
incorporated new changes in trs_list view
SargeKhan Jul 3, 2017
8f98f3f
moved data field from trs header to transfer trs
SargeKhan Jul 4, 2017
ba373fc
merged with 1.0.0
SargeKhan Jul 8, 2017
5111764
Merge branch '624-attach-transaction-asset' into 26-add_data_field_wi…
SargeKhan Jul 8, 2017
1044c30
attached transfer asset query for get transaction
SargeKhan Jul 8, 2017
205b243
updated position of data property as SEND trs asset
SargeKhan Jul 11, 2017
06967f2
changed tab indentation to spaces
SargeKhan Jul 12, 2017
8b92937
merged with dev. and updated jenkins file
SargeKhan Jul 13, 2017
6fe92e1
merged with 624-attach-transaction-asset
SargeKhan Jul 16, 2017
52032fd
removed some inconsistencies
SargeKhan Jul 16, 2017
f5b270a
accept transaction with undefined transfer asset
SargeKhan Jul 16, 2017
d6026a0
use 146-fee-for-optional-data for lisk-js
SargeKhan Jul 16, 2017
109d424
added api tests for transfer asset edge cases
SargeKhan Jul 17, 2017
62e8154
incorporated review changes
SargeKhan Jul 21, 2017
bb5006d
updated lisk-js version to 1.0.0
SargeKhan Jul 25, 2017
e4c3a84
fixed formating and grammatical errors
SargeKhan Jul 30, 2017
28f0fd2
fixed comment for jenkins file
SargeKhan Jul 30, 2017
1615a97
resolved merge conflicts
SargeKhan Jul 30, 2017
4e083df
resolved conflicts with upstream
SargeKhan Jul 30, 2017
8ac83c2
imported lisk-js 1.0.0 from github
Aug 7, 2017
04c0ce5
removed transaction conflicts
Aug 7, 2017
2851ca1
Removed conflicts for logic/transaction
Aug 8, 2017
7d8f7aa
Importing on lisk-js feature branch through npm
Aug 8, 2017
71150cf
Merged with 1.0.0
Aug 8, 2017
e72ec6f
Attach transfer asset for getting trs by id
Aug 8, 2017
3c5cb89
Fixed failing tests
Aug 8, 2017
73a0645
Merge remote-tracking branch 'upstream/1.0.0' into 26-add_data_field_…
Aug 9, 2017
c899949
Remove duplicate peer.transaction tests
Aug 9, 2017
79dada2
Pre-review formating and comment changes
Aug 9, 2017
245605c
Fixed description of transaction test and added new test
Aug 9, 2017
707dc47
Post review changes
Aug 9, 2017
d12c0e6
Fixed formating issues
Aug 11, 2017
bdbe7d3
Correcting grammar
Aug 14, 2017
0570178
Renaming dappAddFee to dappRegistrationFee
Aug 14, 2017
9292bdd
Normalising space
Aug 14, 2017
dd5076c
Creating "for transaction with data field" context
Aug 14, 2017
cf1007d
Revising "calculateFee" example descriptions
Aug 14, 2017
dca0b6f
Merge remote-tracking branch 'upstream/1.0.0' into 26-add_data_field_…
Aug 14, 2017
2cfaa68
Updated migrations data to today
Aug 14, 2017
3bb0497
Updated PR related migrations date to today
Aug 14, 2017
4bb9037
Merge branch '26-add_data_field_with_transaction' of github.com:Sarge…
Aug 14, 2017
e565471
Renamed delgate table properties in recreateFullBlockListView
Aug 14, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ var constants = {
secondsignature: 500000000,
delegate: 2500000000,
multisignature: 500000000,
dapp: 2500000000
dapp: 2500000000,
data: 10000000
},
feeStart: 1,
feeStartVolume: 10000 * 100000000,
Expand Down
115 changes: 107 additions & 8 deletions logic/transfer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

var constants = require('../helpers/constants.js');
var bignum = require('../helpers/bignum.js');
var slots = require('../helpers/slots.js');

// Private fields
var modules;
var modules, library;

/**
* Main transfer logic.
Expand All @@ -13,7 +14,12 @@ var modules;
* @classdesc Main transfer logic.
*/
// Constructor
function Transfer () {}
function Transfer (logger, schema) {
library = {
logger: logger,
schema: schema,
};
}

// Public methods
/**
Expand All @@ -33,7 +39,12 @@ Transfer.prototype.bind = function (accounts) {
* @return {number} fee
*/
Transfer.prototype.calculateFee = function (trs, sender) {
return constants.fees.send;
var fee = new bignum(constants.fees.send);
if (trs.asset && trs.asset.data) {
fee = fee.plus(constants.fees.data);
}

return Number(fee.toString());
};

/**
Expand Down Expand Up @@ -66,11 +77,21 @@ Transfer.prototype.process = function (trs, sender, cb) {
};

/**
* Creates a buffer with asset.transfer.data.
* @param {transaction} trs
* @return {null}
* @return {buffer} buf
* @throws {error} error
*/
Transfer.prototype.getBytes = function (trs) {
return null;
var buf;

try {
buf = (trs.asset && trs.asset.data) ? Buffer.from(trs.asset.data, 'utf8') : null;
} catch (ex) {
throw ex;
}

return buf;
};

/**
Expand Down Expand Up @@ -153,29 +174,107 @@ Transfer.prototype.undoUnconfirmed = function (trs, sender, cb) {
return setImmediate(cb);
};


/**
* Deletes blockId from transaction
* @typedef {Object} transfer
* @property {String} data
*/
Transfer.prototype.schema = {
id: 'transfer',
type: 'object',
properties: {
data: {
type: 'string',
minLength: 1,
maxLength: 64
}
}
};

/**
* Deletes blockId from transaction, and validates schema if asset exists.
* @param {transaction} trs
* @return {transaction}
*/
Transfer.prototype.objectNormalize = function (trs) {
delete trs.blockId;

if (!trs.asset) {
return trs;
}

if (trs.asset.data === null || typeof trs.asset.data === 'undefined') {
delete trs.asset.data;
}

var report = library.schema.validate(trs.asset, Transfer.prototype.schema);

if (!report) {
throw 'Failed to validate transfer schema: ' + library.schema.getLastErrors().map(function (err) {
return err.message;
}).join(', ');
}

return trs;
};

Transfer.prototype.dbTable = 'transfer';

Transfer.prototype.dbFields = [
'data',
'transactionId'
];

/**
* @typedef transferAsset
* @property {String} data
*/

/**
* Checks if asset exists, if so, returns value, otherwise returns null.
* @param {Object} raw
* @return {null}
* @return {transferAsset|null}
*/
Transfer.prototype.dbRead = function (raw) {
if (raw.tf_data) {
return {data: raw.tf_data};
}

return null;
};

/**
* @typedef trsPromise
* @property {string} table
* @property {array} fields
* @property {object} values
*/

/**
* Checks if asset exists, if so, returns transfer table promise, otherwise returns null.
* @param {transaction} trs
* @return {null}
* @return {trsPromise|null}
*/
Transfer.prototype.dbSave = function (trs) {
if (trs.asset && trs.asset.data) {
var data;

try {
data = Buffer.from(trs.asset.data, 'utf8');
} catch (ex) {
throw ex;
}

return {
table: this.dbTable,
fields: this.dbFields,
values: {
data: data,
transactionId: trs.id
}
};
}

return null;
};

Expand Down
4 changes: 2 additions & 2 deletions modules/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Transactions (cb, scope) {
);

__private.assetTypes[transactionTypes.SEND] = library.logic.transaction.attachAssetType(
transactionTypes.SEND, new Transfer()
transactionTypes.SEND, new Transfer(library.logger, library.schema)
);

setImmediate(cb, null, self);
Expand Down Expand Up @@ -240,6 +240,7 @@ __private.getById = function (id, cb) {

var rawTransaction = rows[0];
var queryNames = {};
queryNames[transactionTypes.SEND] = 'getTransferById';
queryNames[transactionTypes.SIGNATURE] = 'getSignatureById';
queryNames[transactionTypes.DELEGATE] = 'getDelegateById';
queryNames[transactionTypes.VOTE] = 'getVotesById';
Expand Down Expand Up @@ -651,7 +652,6 @@ Transactions.prototype.shared = {
}

return setImmediate(cb, null, {transaction: transaction});

});
});
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"istanbul-middleware": "=0.2.2",
"jsdoc": "=3.4.3",
"jsdox": "=0.4.10",
"lisk-js": "=0.4.3",
"lisk-js": "git://github.com/LiskHQ/lisk-js#optional_data_test",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tosch110 @SargeKhan could you explain the reason you aren't using a published verion of lisk-js ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this PR introduces a new field (i.e. data property) with type 0 transaction, which isn't acceptable by the network until lisk core 1.0.0 is released. So, we can't use a published version of lisk-js. @Tosch110 will probably merge this branch with lisk-js 1.0.0 branch, and then I'll update this line.

"mocha": "=3.4.2",
"moment": "=2.18.1",
"pm2": "=2.4.6",
Expand Down
15 changes: 15 additions & 0 deletions sql/migrations/20170814143733_createTransferTrsTable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Create transfer trs table and index.
*/

BEGIN;

CREATE TABLE IF NOT EXISTS "transfer" (
"data" BYTEA NOT NULL,
"transactionId" VARCHAR(20) NOT NULL,
FOREIGN KEY("transactionId") REFERENCES "trs"("id") ON DELETE CASCADE
);

CREATE INDEX IF NOT EXISTS "transfer_trs_id" ON "transfer"("transactionId");

COMMIT;
67 changes: 67 additions & 0 deletions sql/migrations/20170814144034_recreateFullBlockListView.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Recreate full_blocks_list, add join for transfer table.
*/

BEGIN;

DROP VIEW IF EXISTS full_blocks_list;

CREATE VIEW full_blocks_list AS

SELECT b."id" AS "b_id",
b."version" AS "b_version",
b."timestamp" AS "b_timestamp",
b."height" AS "b_height",
b."previousBlock" AS "b_previousBlock",
b."numberOfTransactions" AS "b_numberOfTransactions",
(b."totalAmount")::bigint AS "b_totalAmount",
(b."totalFee")::bigint AS "b_totalFee",
(b."reward")::bigint AS "b_reward",
b."payloadLength" AS "b_payloadLength",
ENCODE(b."payloadHash", 'hex') AS "b_payloadHash",
ENCODE(b."generatorPublicKey", 'hex') AS "b_generatorPublicKey",
ENCODE(b."blockSignature", 'hex') AS "b_blockSignature",
t."id" AS "t_id",
t."rowId" AS "t_rowId",
t."type" AS "t_type",
t."timestamp" AS "t_timestamp",
ENCODE(t."senderPublicKey", 'hex') AS "t_senderPublicKey",
t."senderId" AS "t_senderId",
t."recipientId" AS "t_recipientId",
(t."amount")::bigint AS "t_amount",
(t."fee")::bigint AS "t_fee",
ENCODE(t."signature", 'hex') AS "t_signature",
ENCODE(t."signSignature", 'hex') AS "t_signSignature",
ENCODE(s."publicKey", 'hex') AS "s_publicKey",
d."name" AS "d_username",
v."votes" AS "v_votes",
m."min" AS "m_min",
m."lifetime" AS "m_lifetime",
m."keysgroup" AS "m_keysgroup",
dapp."name" AS "dapp_name",
dapp."description" AS "dapp_description",
dapp."tags" AS "dapp_tags",
dapp."type" AS "dapp_type",
dapp."link" AS "dapp_link",
dapp."category" AS "dapp_category",
dapp."icon" AS "dapp_icon",
it."dappId" AS "in_dappId",
ot."dappId" AS "ot_dappId",
ot."outTransactionId" AS "ot_outTransactionId",
ENCODE(t."requesterPublicKey", 'hex') AS "t_requesterPublicKey",
CONVERT_FROM(tf."data", 'utf8') AS "tf_data",
t."signatures" AS "t_signatures"

FROM blocks b

LEFT OUTER JOIN trs AS t ON t."blockId" = b."id"
LEFT OUTER JOIN delegates AS d ON d."tx_id" = 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 m ON m."transactionId" = t."id"
LEFT OUTER JOIN dapps AS dapp ON dapp."transactionId" = t."id"
LEFT OUTER JOIN intransfer AS it ON it."transactionId" = t."id"
LEFT OUTER JOIN outtransfer AS ot ON ot."transactionId" = t."id"
LEFT OUTER JOIN transfer AS tf ON tf."transactionId" = t."id";

COMMIT;
2 changes: 2 additions & 0 deletions sql/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var TransactionsSql = {

getById: 'SELECT *, ENCODE ("t_senderPublicKey", \'hex\') AS "t_senderPublicKey", ENCODE ("m_recipientPublicKey", \'hex\') AS "m_recipientPublicKey" FROM trs_list WHERE "t_id" = ${id}',

getTransferById: 'SELECT CONVERT_FROM(data, \'utf8\') AS "tf_data" FROM transfer WHERE "transactionId" = ${id}',

getVotesById: 'SELECT votes AS "v_votes" FROM votes WHERE "transactionId" = ${id}',

getDelegateById: 'SELECT username AS "d_username" FROM delegates WHERE "transactionId" = ${id}',
Expand Down
2 changes: 1 addition & 1 deletion test/api/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('GET /api/blocks/getfees', function () {
node.expect(res.body).to.have.property('fees');
node.expect(res.body.fees.send).to.equal(node.fees.transactionFee);
node.expect(res.body.fees.vote).to.equal(node.fees.voteFee);
node.expect(res.body.fees.dapp).to.equal(node.fees.dappAddFee);
node.expect(res.body.fees.dapp).to.equal(node.fees.dappRegistrationFee);
node.expect(res.body.fees.secondsignature).to.equal(node.fees.secondPasswordFee);
node.expect(res.body.fees.delegate).to.equal(node.fees.delegateRegistrationFee);
node.expect(res.body.fees.multisignature).to.equal(node.fees.multisignatureRegistrationFee);
Expand Down
Loading