Skip to content
This repository has been archived by the owner on Jan 24, 2020. It is now read-only.

Commit

Permalink
Run yarn generateConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgordstewart committed Dec 8, 2019
1 parent 5c3cc25 commit 6d6ebe2
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 66 deletions.
13 changes: 10 additions & 3 deletions src/protocols/advance-channel/protocol.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ const config = {
initial: 'waiting',
states: {
waiting: {
entry: 'send',
on: { CHANNEL_UPDATED: { target: 'success', cond: 'advanced' } },
entry: 'sendState',
on: {
CHANNEL_UPDATED: { target: 'success', cond: 'advanced' },
'': { target: 'success', cond: 'advanced' },
},
},
success: { type: 'final' },
},
Expand All @@ -14,5 +17,9 @@ const guards = {
return true;
},
};
const customActions = {};
const customActions = {
sendState: function(ctx) {
return true;
},
};
const machine = Machine(config, { guards, actions: customActions });
69 changes: 59 additions & 10 deletions src/protocols/create-channel/protocol.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@ const config = {
initial: 'initializeChannel',
states: {
initializeChannel: {
entry: function() {
return console.log('CREATING CHANNEL');
},
invoke: { src: 'setChannelId', onDone: 'preFundSetup' },
exit: {
type: 'xstate.assign',
assignment: function(ctx, _a) {
var channelId = _a.channelId;
return __assign(__assign({}, ctx), { channelId: channelId });
exit: [
{
type: 'xstate.assign',
assignment: {
channelId: function(_, event) {
return event.data.channelId;
},
},
},
},
function(ctx) {
return console.log('Sending open channel message');
},
],
},
preFundSetup: {
onEntry: 'sendOpenChannelMessage',
invoke: {
id: 'preFundSetup',
src: 'advanceChannel',
data: function(_a) {
var channelId = _a.channelId;
Expand All @@ -25,7 +34,20 @@ const config = {
},
onDone: 'funding',
},
on: { CHANNEL_CLOSED: 'abort' },
on: {
CHANNEL_CLOSED: 'abort',
CHANNEL_UPDATED: {
actions: {
to: 'preFundSetup',
type: 'xstate.send',
event: function(_, event) {
return event;
},
delay: undefined,
id: '',
},
},
},
},
abort: { type: 'final' },
funding: {
Expand All @@ -40,6 +62,7 @@ const config = {
},
postFundSetup: {
invoke: {
id: 'postFundSetup',
src: 'advanceChannel',
data: function(_a) {
var channelId = _a.channelId;
Expand All @@ -50,10 +73,36 @@ const config = {
},
onDone: 'success',
},
on: {
CHANNEL_UPDATED: {
actions: {
to: 'postFundSetup',
type: 'xstate.send',
event: function(_, event) {
return event;
},
delay: undefined,
id: '',
},
},
},
},
success: {
type: 'final',
entry: {
to: '#_parent',
type: 'xstate.send',
event: { type: 'CHANNEL_CREATED' },
delay: undefined,
id: 'CHANNEL_CREATED',
},
},
success: { type: 'final' },
},
};
const guards = {};
const customActions = {};
const customActions = {
sendOpenChannelMessage: function(ctx) {
return console.log('Sending open channel message');
},
};
const machine = Machine(config, { guards, actions: customActions });
21 changes: 6 additions & 15 deletions src/protocols/direct-funding/protocol.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ const config = {
initial: 'updatePrefundOutcome',
states: {
updatePrefundOutcome: {
on: { '': { target: 'waiting', cond: 'noUpdateNeeded' } },
invoke: {
src: 'ledgerUpdate',
data: function(context) {
return {
targetChannelID: context.targetChannelID,
targetOutcome: preDepositOutcome(
context.targetChannelID,
context.minimalOutcome
),
};
},
data: 'preFundLedgerUpdateParams',
onDone: 'waiting',
},
},
Expand All @@ -33,12 +26,7 @@ const config = {
updatePostFundOutcome: {
invoke: {
src: 'ledgerUpdate',
data: function(context) {
return {
targetChannelID: context.targetChannelID,
targetOutcome: postDepositOutcome(context.targetChannelID),
};
},
data: 'postFundLedgerUpdateParams',
onDone: 'success',
},
},
Expand All @@ -47,6 +35,9 @@ const config = {
},
};
const guards = {
noUpdateNeeded: function(x) {
return true;
},
safeToDeposit: function(x) {
return true;
},
Expand Down
39 changes: 29 additions & 10 deletions src/protocols/funding/protocol.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,44 @@ const config = {
initial: 'determineStrategy',
states: {
determineStrategy: {
on: { PROPOSAL_RECEIVED: { actions: 'assignProposal' } },
on: {
PROPOSAL_RECEIVED: {
actions: {
type: 'xstate.assign',
assignment: function(ctx, _a) {
var data = _a.data;
return __assign(__assign({}, ctx), { peerChoice: data.choice });
},
},
},
},
initial: 'getClientChoice',
states: {
getClientChoice: {
invoke: {
id: 'ask-client-for-choice',
src: 'askClient',
onDone: { actions: ['sendClientChoice', 'assignClientChoice'] },
onDone: {
actions: [
'sendClientChoice',
{
type: 'xstate.assign',
assignment: function(ctx, _a) {
var data = _a.data;
return __assign(__assign({}, ctx), {
clientChoice: data.choice,
});
},
},
],
},
},
onDone: 'wait',
},
wait: {
on: {
'*': [
{
target: 'success',
cond: 'consensus',
actions: 'assignStrategy',
},
{ target: 'success', cond: 'consensus' },
{ target: 'retry', cond: 'disagreement' },
],
},
Expand All @@ -44,9 +63,9 @@ const config = {
{ target: 'fundVirtually', cond: 'virtualStrategyChosen' },
],
},
fundDirectly: { invoke: 'directFunding', onDone: 'success' },
fundIndirectly: { invoke: 'ledgerFunding', onDone: 'success' },
fundVirtually: { invoke: 'virtualFunding', onDone: 'success' },
fundDirectly: { invoke: { src: 'directFunding', onDone: 'success' } },
fundIndirectly: { invoke: { src: 'ledgerFunding', onDone: 'success' } },
fundVirtually: { invoke: { src: 'virtualFunding', onDone: 'success' } },
success: { type: 'final' },
failure: { type: 'final' },
},
Expand Down
105 changes: 96 additions & 9 deletions src/protocols/join-channel/protocol.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,110 @@ const config = {
key: 'join-channel',
initial: 'checkNonce',
states: {
checkNonce: { invoke: { src: 'checkNonce', onDone: 'askClient' } },
checkNonce: {
on: { OPEN_CHANNEL: { target: 'askClient', cond: 'nonceOk' } },
exit: 'storeState',
},
askClient: {
invoke: { src: 'askClient' },
on: { CLOSE_CHANNEL: 'abort', JOIN_CHANNEL: 'funding' },
invoke: {
src: 'askClient',
onDone: [
{
target: 'preFundSetup',
cond: function(_a, event) {
return event.data === 'JOIN_CHANNEL';
},
},
{
target: 'abort',
cond: function(_a, event) {
return event.data === 'CLOSE_CHANNEL';
},
},
],
},
},
abort: { type: 'final' },
preFundSetup: {
invoke: {
id: 'preFundSetup',
src: 'advanceChannel',
data: function(_a) {
var channelId = _a.channelId;
return {
channelId: channelId,
targetTurnNum: n,
};
},
onDone: 'funding',
},
on: {
CHANNEL_UPDATED: {
actions: {
to: 'preFundSetup',
type: 'xstate.send',
event: function(_, event) {
return event;
},
delay: undefined,
id: '',
},
},
},
},
funding: {
invoke: { src: 'funding', data: 'passChannelId' },
onDone: 'postFundSetup',
invoke: {
src: 'funding',
data: function(_a) {
var channelId = _a.channelId;
return { channelId: channelId };
},
onDone: 'postFundSetup',
},
},
postFundSetup: {
invoke: { src: 'advance-channel', data: 'passChannelId' },
onDone: 'success',
invoke: {
id: 'postFundSetup',
src: 'advanceChannel',
data: function(_a) {
var channelId = _a.channelId;
return {
channelId: channelId,
targetTurnNum: n,
};
},
onDone: 'success',
},
on: {
CHANNEL_UPDATED: {
actions: {
to: 'postFundSetup',
type: 'xstate.send',
event: function(_, event) {
return event;
},
delay: undefined,
id: '',
},
},
},
},
success: {
type: 'final',
entry: {
to: '#_parent',
type: 'xstate.send',
event: { type: 'CHANNEL_JOINED' },
delay: undefined,
id: 'CHANNEL_JOINED',
},
},
success: { type: 'final' },
},
};
const guards = {};
const guards = {
nonceOk: function() {
return true;
},
};
const customActions = {};
const machine = Machine(config, { guards, actions: customActions });
19 changes: 1 addition & 18 deletions src/protocols/ledger-defunding/protocol.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,10 @@ const config = {
key: 'ledger-defunding',
initial: 'concludeTarget',
states: {
concludeTarget: {
invoke: {
src: 'concludeChannel',
data: function(context) {
return { channelID: context.ledgerChannelID };
},
onDone: 'defundTarget',
},
},
defundTarget: {
invoke: {
src: 'ledgerUpdate',
data: function(context) {
return {
channelID: context.ledgerChannelID,
outcome: defundedOutcome(
context.ledgerChannelID,
context.targetChannelID
),
};
},
data: 'ledgerUpdateArgs',
onDone: 'success',
},
},
Expand Down
1 change: 0 additions & 1 deletion src/protocols/wallet/protocol.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const config = {
key: 'wallet',
initial: 'running',
context: { processes: [] },
states: {
running: {
on: {
Expand Down

0 comments on commit 6d6ebe2

Please sign in to comment.