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

Commit

Permalink
♻️ Fix make common schema separate for protocol spec
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed Jun 4, 2020
1 parent 8846458 commit c08d2dd
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 187 deletions.
40 changes: 3 additions & 37 deletions protocol-specs/generators/multisignature_registration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
const { signData } = require('@liskhq/lisk-cryptography');
const { Codec } = require('@liskhq/lisk-codec');
const BaseGenerator = require('../base_generator');
const { baseTransactionSchema } = require('../../utils/schema');

const codec = new Codec();

Expand Down Expand Up @@ -100,41 +101,6 @@ const outputBase64Account = account => ({
address: account.address.toString('base64'),
});

const baseSchema = {
$id: 'baseSchema',
type: 'object',
required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'],
properties: {
type: {
dataType: 'uint32',
fieldNumber: 1,
},
nonce: {
dataType: 'uint64',
fieldNumber: 2,
},
fee: {
dataType: 'uint64',
fieldNumber: 3,
},
senderPublicKey: {
dataType: 'bytes',
fieldNumber: 4,
},
asset: {
dataType: 'bytes',
fieldNumber: 5,
},
signatures: {
type: 'array',
items: {
dataType: 'bytes',
},
fieldNumber: 6,
},
},
};

const multisigRegAsset = {
type: 'object',
properties: {
Expand Down Expand Up @@ -162,7 +128,7 @@ const getSignBytes = tx => {
asset: assetBytes,
signatures: [],
};
return codec.encode(baseSchema, signingTx);
return codec.encode(baseTransactionSchema, signingTx);
};

const encode = tx => {
Expand All @@ -171,7 +137,7 @@ const encode = tx => {
...tx,
asset: assetBytes,
};
return codec.encode(baseSchema, txWithAssetBytes);
return codec.encode(baseTransactionSchema, txWithAssetBytes);
};

const sortKeysAscending = publicKeys =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
signDataWithPrivateKey,
} = require('@liskhq/lisk-cryptography');
const { Codec } = require('@liskhq/lisk-codec');
const { baseTransactionSchema } = require('../../utils/schema');

const BaseGenerator = require('../base_generator');

Expand All @@ -31,41 +32,6 @@ const networkIdentifier = Buffer.from(
'hex',
);

const baseSchema = {
$id: 'baseSchema',
type: 'object',
required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'],
properties: {
type: {
dataType: 'uint32',
fieldNumber: 1,
},
nonce: {
dataType: 'uint64',
fieldNumber: 2,
},
fee: {
dataType: 'uint64',
fieldNumber: 3,
},
senderPublicKey: {
dataType: 'bytes',
fieldNumber: 4,
},
asset: {
dataType: 'bytes',
fieldNumber: 5,
},
signatures: {
type: 'array',
items: {
dataType: 'bytes',
},
fieldNumber: 6,
},
},
};

const pomAsset = {
$id: 'asset/pom',
type: 'object',
Expand Down Expand Up @@ -164,7 +130,7 @@ const getSignBytes = tx => {
asset: assetBytes,
signatures: [],
};
return codec.encode(baseSchema, signingTx);
return codec.encode(baseTransactionSchema, signingTx);
};

const encode = tx => {
Expand All @@ -173,7 +139,7 @@ const encode = tx => {
...tx,
asset: assetBytes,
};
return codec.encode(baseSchema, txWithAssetBytes);
return codec.encode(baseTransactionSchema, txWithAssetBytes);
};

const createSignatureObject = (txBuffer, account) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
const { signData } = require('@liskhq/lisk-cryptography');
const { Codec } = require('@liskhq/lisk-codec');
const BaseGenerator = require('../base_generator');
const { baseTransactionSchema } = require('../../utils/schema');

const codec = new Codec();

Expand Down Expand Up @@ -84,41 +85,6 @@ const networkIdentifier = Buffer.from(
'hex',
);

const baseSchema = {
$id: 'baseSchema',
type: 'object',
required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'],
properties: {
type: {
dataType: 'uint32',
fieldNumber: 1,
},
nonce: {
dataType: 'uint64',
fieldNumber: 2,
},
fee: {
dataType: 'uint64',
fieldNumber: 3,
},
senderPublicKey: {
dataType: 'bytes',
fieldNumber: 4,
},
asset: {
dataType: 'bytes',
fieldNumber: 5,
},
signatures: {
type: 'array',
items: {
dataType: 'bytes',
},
fieldNumber: 6,
},
},
};

const balanceTransferAsset = {
type: 'object',
$id: 'balanceTransferAsset',
Expand Down Expand Up @@ -156,7 +122,7 @@ const generateValidTransferTransaction = () => {
asset: assetBytes,
signatures: [],
};
const signingBytes = codec.encode(baseSchema, signingTx);
const signingBytes = codec.encode(baseTransactionSchema, signingTx);

const signature = Buffer.from(
signData(
Expand All @@ -166,7 +132,7 @@ const generateValidTransferTransaction = () => {
'hex',
);

const encodedTx = codec.encode(baseSchema, {
const encodedTx = codec.encode(baseTransactionSchema, {
...tx,
asset: assetBytes,
signatures: [signature],
Expand Down Expand Up @@ -207,7 +173,7 @@ const generateValidDelegateTransaction = () => {
asset: assetBytes,
signatures: [],
};
const signingBytes = codec.encode(baseSchema, signingTx);
const signingBytes = codec.encode(baseTransactionSchema, signingTx);

const signature = Buffer.from(
signData(
Expand All @@ -217,7 +183,7 @@ const generateValidDelegateTransaction = () => {
'hex',
);

const encodedTx = codec.encode(baseSchema, {
const encodedTx = codec.encode(baseTransactionSchema, {
...tx,
asset: assetBytes,
signatures: [signature],
Expand Down
40 changes: 3 additions & 37 deletions protocol-specs/generators/unlocking_transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
const { signData } = require('@liskhq/lisk-cryptography');
const { Codec } = require('@liskhq/lisk-codec');
const BaseGenerator = require('../base_generator');
const { baseTransactionSchema } = require('../../utils/schema');

const codec = new Codec();

Expand Down Expand Up @@ -177,41 +178,6 @@ const delegateAccounts = [
},
];

const baseSchema = {
$id: 'baseSchema',
type: 'object',
required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'],
properties: {
type: {
dataType: 'uint32',
fieldNumber: 1,
},
nonce: {
dataType: 'uint64',
fieldNumber: 2,
},
fee: {
dataType: 'uint64',
fieldNumber: 3,
},
senderPublicKey: {
dataType: 'bytes',
fieldNumber: 4,
},
asset: {
dataType: 'bytes',
fieldNumber: 5,
},
signatures: {
type: 'array',
items: {
dataType: 'bytes',
},
fieldNumber: 6,
},
},
};

const assetSchema = {
$id: 'asset/unlock',
type: 'object',
Expand Down Expand Up @@ -242,7 +208,7 @@ const getSignBytes = tx => {
asset: assetBytes,
signatures: [],
};
return codec.encode(baseSchema, signingTx);
return codec.encode(baseTransactionSchema, signingTx);
};

const encode = tx => {
Expand All @@ -251,7 +217,7 @@ const encode = tx => {
...tx,
asset: assetBytes,
};
return codec.encode(baseSchema, txWithAssetBytes);
return codec.encode(baseTransactionSchema, txWithAssetBytes);
};

const generateValidUpvoteTransaction = () => {
Expand Down
40 changes: 3 additions & 37 deletions protocol-specs/generators/vote_transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
const { signData } = require('@liskhq/lisk-cryptography');
const { Codec } = require('@liskhq/lisk-codec');
const BaseGenerator = require('../base_generator');
const { baseTransactionSchema } = require('../../utils/schema');

const codec = new Codec();

Expand Down Expand Up @@ -217,41 +218,6 @@ const delegateAccounts = [
},
];

const baseSchema = {
$id: 'baseSchema',
type: 'object',
required: ['type', 'nonce', 'fee', 'senderPublicKey', 'asset'],
properties: {
type: {
dataType: 'uint32',
fieldNumber: 1,
},
nonce: {
dataType: 'uint64',
fieldNumber: 2,
},
fee: {
dataType: 'uint64',
fieldNumber: 3,
},
senderPublicKey: {
dataType: 'bytes',
fieldNumber: 4,
},
asset: {
dataType: 'bytes',
fieldNumber: 5,
},
signatures: {
type: 'array',
items: {
dataType: 'bytes',
},
fieldNumber: 6,
},
},
};

const assetSchema = {
type: 'object',
properties: {
Expand Down Expand Up @@ -280,7 +246,7 @@ const getSignBytes = tx => {
asset: assetBytes,
signatures: [],
};
return codec.encode(baseSchema, signingTx);
return codec.encode(baseTransactionSchema, signingTx);
};

const encode = tx => {
Expand All @@ -289,7 +255,7 @@ const encode = tx => {
...tx,
asset: assetBytes,
};
return codec.encode(baseSchema, txWithAssetBytes);
return codec.encode(baseTransactionSchema, txWithAssetBytes);
};

const generateValidUpvoteTransaction = () => {
Expand Down
Loading

0 comments on commit c08d2dd

Please sign in to comment.