Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
martiliones committed Feb 9, 2022
1 parent 4a8f497 commit 6e05144
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
10 changes: 4 additions & 6 deletions groups/delegateNew.js → groups/newDelegate.js
Expand Up @@ -9,13 +9,11 @@ const DEFAULT_SEND_TOKENS_RETRIES = 4; // How much re-tries for send tokens requ

module.exports = (nodeManager) => {
/**
* Creates Token Transfer transaction, signs it, and broadcasts to ADAMANT network
* See https://github.com/Adamant-im/adamant/wiki/Transaction-Types#type-0-token-transfer-transaction
* Registers user account as delegate
* @param {string} passPhrase Senders's passPhrase. Sender's address will be derived from it.
* @param {string} addressOrPublicKey Recipient's ADAMANT address or public key.
* Address is preferred, as if we get public key, we should derive address from it.
* @param {string, number} amount Amount to send
* @param {boolean} isAmountInADM If amount specified in ADM, or in sats (10^-8 ADM)
* @param {string} username Delegate name you want to register with.
* It must be unique in ADAMANT blockchain. It should not be similar to ADAMANT address.
* Delegate name can only contain alphanumeric characters and symbols !@$&_.
* @param {number} maxRetries How much times to retry request
* @returns {Promise} Request results
*/
Expand Down
9 changes: 3 additions & 6 deletions groups/voteForDelegate.js
Expand Up @@ -9,13 +9,10 @@ const DEFAULT_SEND_TOKENS_RETRIES = 4; // How much re-tries for send tokens requ

module.exports = (nodeManager) => {
/**
* Creates Token Transfer transaction, signs it, and broadcasts to ADAMANT network
* See https://github.com/Adamant-im/adamant/wiki/Transaction-Types#type-0-token-transfer-transaction
* Creates votes for delegate transaction, signs it, and broadcasts to ADAMANT network
* See https://github.com/Adamant-im/adamant/wiki/Transaction-Types#type-3-vote-for-delegate-transaction
* @param {string} passPhrase Senders's passPhrase. Sender's address will be derived from it.
* @param {string} addressOrPublicKey Recipient's ADAMANT address or public key.
* Address is preferred, as if we get public key, we should derive address from it.
* @param {string, number} amount Amount to send
* @param {boolean} isAmountInADM If amount specified in ADM, or in sats (10^-8 ADM)
* @param {string[]} votes PublicKeys for upvote and downvote
* @param {number} maxRetries How much times to retry request
* @returns {Promise} Request results
*/
Expand Down
1 change: 1 addition & 0 deletions helpers/constants.js
Expand Up @@ -32,6 +32,7 @@ module.exports = {
RE_BASE64: /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/,
RE_ADM_ADDRESS: /^U([0-9]{6,})$/,
RE_ADM_VOTE: /^(\+|-)[a-fA-F0-9]{64}$/,
RE_ADM_DELEGATE_NAME: /^[\w!@$&_]*$/,
RE_BTC_ADDRESS: /^(bc1|[13])[a-km-zA-HJ-NP-Z02-9]{25,39}$/,
RE_DASH_ADDRESS: /^[7X][1-9A-HJ-NP-Za-km-z]{33,}$/,
RE_DOGE_ADDRESS: /^[A|D|9][A-Z0-9]([0-9a-zA-Z]{9,})$/,
Expand Down
2 changes: 1 addition & 1 deletion helpers/validator.js
Expand Up @@ -126,7 +126,7 @@ module.exports = {
return false;
}

return /^[\w!@$&_]*$/.test(name);
return constants.RE_ADM_DELEGATE_NAME.test(name);
},

AdmToSats(amount) {
Expand Down
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -2,7 +2,7 @@ const constants = require('./helpers/constants.js');
const get = require('./groups/get');
const getPublicKey = require('./groups/getPublicKey');
const decodeMsg = require('./groups/decodeMsg');
const delegateNew = require('./groups/delegateNew');
const newDelegate = require('./groups/newDelegate');
const voteForDelegate = require('./groups/voteForDelegate');
const sendTokens = require('./groups/sendTokens');
const sendMessage = require('./groups/sendMessage');
Expand All @@ -27,7 +27,7 @@ module.exports = (params, log) => {
getPublicKey: getPublicKey(nodeManager),
sendTokens: sendTokens(nodeManager),
sendMessage: sendMessage(nodeManager),
delegateNew: delegateNew(nodeManager),
newDelegate: newDelegate(nodeManager),
voteForDelegate: voteForDelegate(nodeManager),
decodeMsg,
eth,
Expand Down

0 comments on commit 6e05144

Please sign in to comment.