Skip to content

Commit

Permalink
feat(Transaction Builder): Add serializations for transactions introd… (
Browse files Browse the repository at this point in the history
#416)

* feat(Transaction Builder): Add serializations for transactions introduced in fortuna release

* Fix lint errors
  • Loading branch information
mpowaga authored and nduchak committed May 17, 2019
1 parent 668e7f1 commit fd7b8ce
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions es/tx/builder/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ const ACCOUNT_TX = [
TX_FIELD('balance', FIELD_TYPES.int)
]

const ACCOUNT_TX_2 = [
...BASE_TX,
TX_FIELD('flags', FIELD_TYPES.int),
TX_FIELD('nonce', FIELD_TYPES.int),
TX_FIELD('balance', FIELD_TYPES.int),
TX_FIELD('gaContract', FIELD_TYPES.id, 'ct'),
TX_FIELD('gaAuthFun', FIELD_TYPES.binary, 'cb')
]

const SPEND_TX = [
...BASE_TX,
TX_FIELD('senderId', FIELD_TYPES.id, 'ak'),
Expand Down Expand Up @@ -610,6 +619,24 @@ const CHANNEL_TX = [
TX_FIELD('lockedUntil', FIELD_TYPES.int)
]

const CHANNEL_TX_2 = [
...BASE_TX,
TX_FIELD('initiator', FIELD_TYPES.id, 'ak'),
TX_FIELD('responder', FIELD_TYPES.id, 'ak'),
TX_FIELD('channelAmount', FIELD_TYPES.int),
TX_FIELD('initiatorAmount', FIELD_TYPES.int),
TX_FIELD('responderAmount', FIELD_TYPES.int),
TX_FIELD('channelReserve', FIELD_TYPES.int),
TX_FIELD('delegateIds', FIELD_TYPES.ids),
TX_FIELD('stateHash', FIELD_TYPES.hex),
TX_FIELD('round', FIELD_TYPES.int),
TX_FIELD('soloRound', FIELD_TYPES.int),
TX_FIELD('lockPeriod', FIELD_TYPES.int),
TX_FIELD('lockedUntil', FIELD_TYPES.int),
TX_FIELD('initiatorAuth', FIELD_TYPES.binary, 'cb'),
TX_FIELD('responderAuth', FIELD_TYPES.binary, 'cb')
]

const CHANNEL_SNAPSHOT_SOLO_TX = [
...BASE_TX,
TX_FIELD('channelId', FIELD_TYPES.id, 'ch'),
Expand Down Expand Up @@ -723,7 +750,8 @@ const ACCOUNTS_TREE_TX = [

export const TX_SERIALIZATION_SCHEMA = {
[TX_TYPE.account]: {
1: TX_SCHEMA_FIELD(ACCOUNT_TX, OBJECT_TAG_ACCOUNT)
1: TX_SCHEMA_FIELD(ACCOUNT_TX, OBJECT_TAG_ACCOUNT),
2: TX_SCHEMA_FIELD(ACCOUNT_TX_2, OBJECT_TAG_ACCOUNT)
},
[TX_TYPE.signed]: {
1: TX_SCHEMA_FIELD(SIGNED_TX, OBJECT_TAG_SIGNED_TRANSACTION)
Expand Down Expand Up @@ -796,7 +824,8 @@ export const TX_SERIALIZATION_SCHEMA = {
2: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_TX_2, OBJECT_TAG_CHANNEL_OFFCHAIN_TX)
},
[TX_TYPE.channel]: {
1: TX_SCHEMA_FIELD(CHANNEL_TX, OBJECT_TAG_CHANNEL)
1: TX_SCHEMA_FIELD(CHANNEL_TX, OBJECT_TAG_CHANNEL),
2: TX_SCHEMA_FIELD(CHANNEL_TX_2, OBJECT_TAG_CHANNEL)
},
[TX_TYPE.channelSnapshotSolo]: {
1: TX_SCHEMA_FIELD(CHANNEL_SNAPSHOT_SOLO_TX, OBJECT_TAG_CHANNEL_SNAPSHOT_SOLO_TX)
Expand Down Expand Up @@ -850,7 +879,8 @@ export const TX_SERIALIZATION_SCHEMA = {

export const TX_DESERIALIZATION_SCHEMA = {
[OBJECT_TAG_ACCOUNT]: {
1: TX_SCHEMA_FIELD(ACCOUNT_TX, OBJECT_TAG_ACCOUNT)
1: TX_SCHEMA_FIELD(ACCOUNT_TX, OBJECT_TAG_ACCOUNT),
2: TX_SCHEMA_FIELD(ACCOUNT_TX_2, OBJECT_TAG_ACCOUNT)
},
[OBJECT_TAG_SIGNED_TRANSACTION]: {
1: TX_SCHEMA_FIELD(SIGNED_TX, OBJECT_TAG_SIGNED_TRANSACTION)
Expand Down Expand Up @@ -923,7 +953,8 @@ export const TX_DESERIALIZATION_SCHEMA = {
2: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_TX_2, OBJECT_TAG_CHANNEL_OFFCHAIN_TX)
},
[OBJECT_TAG_CHANNEL]: {
1: TX_SCHEMA_FIELD(CHANNEL_TX, OBJECT_TAG_CHANNEL)
1: TX_SCHEMA_FIELD(CHANNEL_TX, OBJECT_TAG_CHANNEL),
2: TX_SCHEMA_FIELD(CHANNEL_TX_2, OBJECT_TAG_CHANNEL)
},
[OBJECT_TAG_CHANNEL_SNAPSHOT_SOLO_TX]: {
1: TX_SCHEMA_FIELD(CHANNEL_SNAPSHOT_SOLO_TX, OBJECT_TAG_CHANNEL_SNAPSHOT_SOLO_TX)
Expand Down

0 comments on commit fd7b8ce

Please sign in to comment.