Created
March 10, 2016 06:35
-
-
Save matsuou1/c835952d1488aa245a0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function serializeMultiSigTransferTransaction (entity) { | |
var r = new ArrayBuffer(512 + 2764); | |
var d = new Uint32Array(r); | |
var b = new Uint8Array(r); | |
// Common transaction part of the byte array | |
// 1.Trransaction type:4byte(integer). | |
d[0] = entity['type']; | |
// 2.Version:4byte | |
d[1] = entity['version']; | |
// 3.Timestamp:4byte(integer) | |
d[2] = entity['timeStamp']; | |
var temp = hex2ua(entity['signer']); | |
// 4.Length of public key byte array(always 32):4byte(integer) | |
d[3] = temp.length; | |
var e = 16; | |
// 5. public key bytes of signer:32 bytes | |
for (var j = 0; j<temp.length; ++j) { b[e++] = temp[j]; } | |
// Transaction | |
var i = e / 4; | |
// 6.Fee(micro nem):8 byte | |
d[i++] = entity['fee']; | |
d[i++] = Math.floor((entity['fee'] / 0x100000000)); | |
// 7.Deadline:4byte(integer) | |
d[i++] = entity['deadline']; | |
e += 12; | |
// Aggregate modification transaction part | |
// Number of cosignatory modifications | |
d[i++] = entity['modifications'].length; | |
e += 4; | |
// The following part is repeated for every cosignatory modification | |
for(var h = 0; h < entity['modifications'].length;h++) { | |
i = e / 4; | |
// 1.Length of cosignatory modification structure:4byte(integer) | |
d[i++] = 0x28; | |
// 2.Modification type:4byte (integer) | |
// Add cosignatory:0x01 , Delete cosignatory:0x02 | |
d[i++] = entity['modifications'][h]['modificationType']; | |
// Lenght of cosignatory's public key byte array(always 32):4bytes(integer) | |
temp = hex2ua(entity['modifications'][h]['cosignatoryAccount']); | |
d[i++] = temp.length; | |
e += 12; | |
// Public key bytes of cosignatory:32bytes console.log("cosignatoryAccount = " + temp); | |
for (var j = 0; j<temp.length; ++j) { b[e++] = temp[j]; } | |
} | |
i = e / 4; | |
// Length of minimum cosignatories modification structure:4bytes(integer) | |
d[i++] = 4; | |
// Relative change : 4bytes(integer) | |
d[i++] = entity['minCosignatories']['relativeChange']; | |
e += 8; | |
return new Uint8Array(r, 0, e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment