Skip to content

Commit

Permalink
feat(TX): encode payload as base64 (#460)
Browse files Browse the repository at this point in the history
* feat(Tx): encode payload as base64 with `ba` prefix

* feat(TX): Deserialize `payload` from `spend` tx as base64 with `ba` prefix

* fix(TxValidator): Fix validator for Channel on-chain transactions
  • Loading branch information
nduchak authored Jun 6, 2019
1 parent 557ded9 commit ad490af
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TAG=v3.0.0-rc.1
TAG=v3.0.1
COMPILER_TAG=v3.0.0
2 changes: 1 addition & 1 deletion es/tx/builder/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { BigNumber } from 'bignumber.js'

export const createSalt = salt

const base64Types = ['tx', 'st', 'ss', 'pi', 'ov', 'or', 'cb', 'cs']
const base64Types = ['tx', 'st', 'ss', 'pi', 'ov', 'or', 'cb', 'cs', 'ba']

/**
* Build a contract public key
Expand Down
3 changes: 3 additions & 0 deletions es/tx/builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function deserializeField (value, type, prefix) {
return encode(value, prefix)
case FIELD_TYPES.string:
return value.toString()
case FIELD_TYPES.payload:
return encode(value, 'ba')
case FIELD_TYPES.pointers:
return readPointers(value)
case FIELD_TYPES.rlpBinary:
Expand Down Expand Up @@ -95,6 +97,7 @@ function serializeField (value, type, prefix) {
return Buffer.from(value, 'hex')
case FIELD_TYPES.signatures:
return value.map(Buffer.from)
case FIELD_TYPES.payload:
case FIELD_TYPES.string:
return toBytes(value)
case FIELD_TYPES.pointers:
Expand Down
5 changes: 3 additions & 2 deletions es/tx/builder/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ export const FIELD_TYPES = {
proofOfInclusion: 'proofOfInclusion',
mptree: 'mptree',
callReturnType: 'callReturnType',
ctVersion: 'ctVersion'
ctVersion: 'ctVersion',
payload: 'payload'
}

// FEE CALCULATION
Expand Down Expand Up @@ -341,7 +342,7 @@ const SPEND_TX = [
TX_FIELD('fee', FIELD_TYPES.int),
TX_FIELD('ttl', FIELD_TYPES.int),
TX_FIELD('nonce', FIELD_TYPES.int),
TX_FIELD('payload', FIELD_TYPES.string)
TX_FIELD('payload', FIELD_TYPES.payload)
]

const SIGNED_TX = [
Expand Down
2 changes: 1 addition & 1 deletion es/tx/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async function unpackAndVerify (txHash, { networkId } = {}) {
}

const getOwnerPublicKey = (tx) =>
tx[['senderId', 'accountId', 'ownerId', 'callerId', 'oracleId'].find(key => tx[key])].replace('ok_', 'ak_')
tx[['senderId', 'accountId', 'ownerId', 'callerId', 'oracleId', 'fromId'].find(key => tx[key])].replace('ok_', 'ak_')

/**
* Verify transaction (verify nonce, ttl, fee, signature, account balance)
Expand Down

0 comments on commit ad490af

Please sign in to comment.