Skip to content

Commit

Permalink
feat(state channels): allow to pass metadata to transfer update (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpowaga authored and nduchak committed Nov 6, 2019
1 parent acba133 commit d7c2ef1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions es/channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function id () {
* @param {String} to - Receiver's public address
* @param {Number} amount - Transaction amount
* @param {Function} sign - Function which verifies and signs offchain transaction
* @param {Array<String>} metadata
* @return {Promise<Object>}
* @example channel.update(
* 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
Expand All @@ -124,7 +125,7 @@ function id () {
* }
* )
*/
function update (from, to, amount, sign) {
function update (from, to, amount, sign, metadata) {
return new Promise((resolve, reject) => {
enqueueAction(
this,
Expand All @@ -133,7 +134,7 @@ function update (from, to, amount, sign) {
send(channel, {
jsonrpc: '2.0',
method: 'channels.update.new',
params: { from, to, amount }
params: { from, to, amount, meta: metadata }
})
return {
handler: handlers.awaitingOffChainTx,
Expand Down
21 changes: 21 additions & 0 deletions test/integration/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,27 @@ describe('Channel', function () {
})
})

it('can post update with metadata', async () => {
responderShouldRejectUpdate = true
const meta = 'meta 1'
const sign = sinon.spy(initiator.signTransaction.bind(initiator))
await initiatorCh.update(
await initiator.address(),
await responder.address(),
100,
sign,
[meta]
)
sign.firstCall.args[1].updates.should.eql([
sign.firstCall.args[1].updates[0],
{ data: meta, op: 'OffChainMeta'}
])
responderSign.firstCall.args[2].updates.should.eql([
responderSign.firstCall.args[2].updates[0],
{ data: meta, op: 'OffChainMeta'}
])
})

it('can get proof of inclusion', async () => {
const initiatorAddr = await initiator.address()
const responderAddr = await responder.address()
Expand Down

0 comments on commit d7c2ef1

Please sign in to comment.