Skip to content

Commit

Permalink
feat(State Channels): Make state channels compatible with aeternity v… (
Browse files Browse the repository at this point in the history
#415)

* feat(State Channels): Make state channels compatible with aeternity v3.0.0

* Fix lint error
  • Loading branch information
mpowaga authored and nduchak committed May 17, 2019
1 parent 46027cd commit 668e7f1
Show file tree
Hide file tree
Showing 4 changed files with 436 additions and 115 deletions.
18 changes: 14 additions & 4 deletions es/channel/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ channelOpen.enter = (channel) => {
export async function awaitingOffChainTx (channel, message, state) {
if (message.method === 'channels.sign.update') {
const { sign } = state
const signedTx = await sign(message.params.data.tx)
const signedTx = await sign(message.params.data.tx, { updates: message.params.data.updates })
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } })
return { handler: awaitingOffChainUpdate, state }
}
Expand Down Expand Up @@ -194,7 +194,11 @@ export async function awaitingTxSignRequest (channel, message, state) {
// eslint-disable-next-line no-useless-escape
const [, tag] = message.method.match(/^channels\.sign\.([^\.]+)$/) || []
if (tag) {
const signedTx = await options.get(channel).sign(tag, message.params.data.tx)
const signedTx = await options.get(channel).sign(
tag,
message.params.data.tx,
{ updates: message.params.data.updates }
)
if (signedTx) {
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } })
return { handler: channelOpen }
Expand Down Expand Up @@ -256,7 +260,10 @@ export function awaitingLeave (channel, message, state) {

export async function awaitingWithdrawTx (channel, message, state) {
if (message.method === 'channels.sign.withdraw_tx') {
const signedTx = await Promise.resolve(state.sign(message.params.data.tx))
const signedTx = await Promise.resolve(state.sign(
message.params.data.tx,
{ updates: message.params.data.updates }
))
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { tx: signedTx } })
return { handler: awaitingWithdrawCompletion, state }
}
Expand Down Expand Up @@ -296,7 +303,10 @@ export function awaitingWithdrawCompletion (channel, message, state) {

export async function awaitingDepositTx (channel, message, state) {
if (message.method === 'channels.sign.deposit_tx') {
const signedTx = await Promise.resolve(state.sign(message.params.data.tx))
const signedTx = await Promise.resolve(state.sign(
message.params.data.tx,
{ updates: message.params.data.updates }
))
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { tx: signedTx } })
return { handler: awaitingDepositCompletion, state }
}
Expand Down
11 changes: 9 additions & 2 deletions es/tx/builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ export function buildTx (params, type, { excludeKeys = [], prefix = 'tx' } = {})
if (!TX_SERIALIZATION_SCHEMA[type]) {
throw new Error('Transaction serialization not implemented for ' + type)
}
const [schema, tag] = TX_SERIALIZATION_SCHEMA[type]
if (!TX_SERIALIZATION_SCHEMA[type][VSN]) {
throw new Error('Transaction serialization not implemented for ' + type + ' version ' + VSN)
}
const [schema, tag] = TX_SERIALIZATION_SCHEMA[type][VSN]
const binary = buildRawTx({ ...params, VSN, tag }, schema, { excludeKeys }).filter(e => e !== undefined)

const rlpEncoded = rlp.encode(binary)
Expand All @@ -327,7 +330,11 @@ export function unpackTx (encodedTx, fromRlpBinary = false) {
if (!TX_DESERIALIZATION_SCHEMA[objId]) {
return { message: 'Transaction deserialization not implemented for tag ' + objId }
}
const [schema] = TX_DESERIALIZATION_SCHEMA[objId]
const vsn = readInt(binary[1])
if (!TX_DESERIALIZATION_SCHEMA[objId][vsn]) {
return { message: 'Transaction deserialization not implemented for tag ' + objId + ' version ' + vsn }
}
const [schema] = TX_DESERIALIZATION_SCHEMA[objId][vsn]

return { txType: OBJECT_ID_TX_TYPE[objId], tx: unpackRawTx(binary, schema), rlpEncoded, binary }
}
Expand Down
Loading

0 comments on commit 668e7f1

Please sign in to comment.