Skip to content

Commit

Permalink
Add multisign helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
wltsmrz committed Sep 13, 2015
1 parent a53249c commit 7e886b3
Show file tree
Hide file tree
Showing 8 changed files with 438 additions and 103 deletions.
42 changes: 31 additions & 11 deletions src/core/binformat.js
@@ -1,6 +1,8 @@
'use strict';

/*eslint no-multi-spaces:0,space-in-brackets:0,key-spacing:0,comma-spacing:0*/
/*eslint-disable max-len,spaced-comment,array-bracket-spacing,key-spacing*/
/*eslint-disable no-multi-spaces,comma-spacing*/
/*eslint-disable no-multi-spaces:0,space-in-brackets:0,key-spacing:0,comma-spacing:0*/

/**
* Data type map.
Expand Down Expand Up @@ -52,7 +54,8 @@ const FIELDS_MAP = exports.fields = {
// Common types
1: { // Int16
1: 'LedgerEntryType',
2: 'TransactionType'
2: 'TransactionType',
3: 'SignerWeight'
},
2: { // Int32
2: 'Flags',
Expand Down Expand Up @@ -87,7 +90,9 @@ const FIELDS_MAP = exports.fields = {
31: 'ReserveBase',
32: 'ReserveIncrement',
33: 'SetFlag',
34: 'ClearFlag'
34: 'ClearFlag',
35: 'SignerQuorum',
38: 'SignerListID'
},
3: { // Int64
1: 'IndexNext',
Expand Down Expand Up @@ -166,13 +171,15 @@ const FIELDS_MAP = exports.fields = {
7: 'FinalFields',
8: 'NewFields',
9: 'TemplateEntry',
10: 'Memo'
10: 'Memo',
11: 'SignerEntry',
16: 'Signer'
},
15: { // Array
1: undefined, // end of Array
2: 'SigningAccounts',
3: 'TxnSignatures',
4: 'Signatures',
3: 'Signers',
4: 'SignerEntries',
5: 'Template',
6: 'Necessary',
7: 'Sufficient',
Expand Down Expand Up @@ -202,7 +209,7 @@ const FIELDS_MAP = exports.fields = {
}
};

let INVERSE_FIELDS_MAP = exports.fieldsInverseMap = { };
const INVERSE_FIELDS_MAP = exports.fieldsInverseMap = { };

Object.keys(FIELDS_MAP).forEach(function(k1) {
Object.keys(FIELDS_MAP[k1]).forEach(function(k2) {
Expand All @@ -211,8 +218,8 @@ Object.keys(FIELDS_MAP).forEach(function(k1) {
});

const REQUIRED = exports.REQUIRED = 0,
OPTIONAL = exports.OPTIONAL = 1,
DEFAULT = exports.DEFAULT = 2;
OPTIONAL = exports.OPTIONAL = 1,
DEFAULT = exports.DEFAULT = 2;

const base = [
[ 'TransactionType' , REQUIRED ],
Expand All @@ -226,7 +233,8 @@ const base = [
[ 'SigningPubKey' , REQUIRED ],
[ 'TxnSignature' , OPTIONAL ],
[ 'AccountTxnID' , OPTIONAL ],
[ 'Memos' , OPTIONAL ]
[ 'Memos' , OPTIONAL ],
[ 'Signers' , OPTIONAL ]
];

exports.tx = {
Expand Down Expand Up @@ -296,6 +304,10 @@ exports.tx = {
]),
TicketCancel: [11].concat(base, [
[ 'TicketID' , REQUIRED ]
]),
SignerListSet: [12].concat(base, [
['SignerQuorum', REQUIRED],
['SignerEntries', OPTIONAL]
])
};

Expand Down Expand Up @@ -396,7 +408,15 @@ exports.ledger = {
['LedgerIndex', OPTIONAL],
['Balance', REQUIRED],
['LowLimit', REQUIRED],
['HighLimit', REQUIRED]])
['HighLimit', REQUIRED]]),
SignerList: [83].concat(sleBase,[
['OwnerNode', REQUIRED],
['SignerQuorum', REQUIRED],
['SignerEntries', REQUIRED],
['SignerListID', REQUIRED],
['PreviousTxnID', REQUIRED],
['PreviousTxnLgrSeq', REQUIRED]
])
};

exports.metadata = [
Expand Down
2 changes: 2 additions & 0 deletions src/core/hashprefixes.js
Expand Up @@ -30,6 +30,8 @@ exports.HASH_LEAF_NODE = 0x4D4C4E00; // 'MLN'
exports.HASH_TX_SIGN = 0x53545800; // 'STX'
// inner transaction to sign (TESTNET)
exports.HASH_TX_SIGN_TESTNET = 0x73747800; // 'stx'
// inner transaction to multisign
exports.HASH_TX_MULTISIGN = 0x534D5400; // 'SMT'

Object.keys(exports).forEach(function(k) {
exports[k + '_BYTES'] = toBytes(exports[k]);
Expand Down
3 changes: 2 additions & 1 deletion src/core/index.js
Expand Up @@ -24,7 +24,8 @@ exports._test = {
Log: require('./log'),
PathFind: require('./pathfind').PathFind,
TransactionManager: require('./transactionmanager').TransactionManager,
RangeSet: require('./rangeset').RangeSet
RangeSet: require('./rangeset').RangeSet,
HashPrefixes: require('./hashprefixes')
};

exports.types = require('./serializedtypes');
3 changes: 2 additions & 1 deletion src/core/remote.js
Expand Up @@ -2271,7 +2271,8 @@ Remote.prototype.createTransaction = function(type, options = {}) {
TrustSet: transaction.trustSet,
OfferCreate: transaction.offerCreate,
OfferCancel: transaction.offerCancel,
SetRegularKey: transaction.setRegularKey
SetRegularKey: transaction.setRegularKey,
SignerListSet: transaction.setSignerList
};

const transactionConstructor = constructorMap[type];
Expand Down

0 comments on commit 7e886b3

Please sign in to comment.