Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(state channels): allow to pass metadata to transfer update #755

Merged
merged 2 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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