Skip to content

Commit

Permalink
Adjudicator: Merge conclude and concludeFinal
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgeihs committed Oct 6, 2021
1 parent 6bc9781 commit 3fa5c35
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 64 deletions.
38 changes: 0 additions & 38 deletions channel/adjudicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,47 +97,9 @@ func (a *Adjudicator) Withdraw(ctx context.Context, req channel.AdjudicatorReq,
}

func (a *Adjudicator) conclude(ctx context.Context, req channel.AdjudicatorReq) error {
if req.Tx.State.IsFinal {
return a.concludeFinal(ctx, req)
}
return a.concludeDispute(ctx, req)
}

func (a *Adjudicator) concludeFinal(ctx context.Context, req channel.AdjudicatorReq) error {
return a.callAdjudicator(ctx, binding.NewConcludeExecuteMsg, req)
}

func (a *Adjudicator) concludeDispute(ctx context.Context, req channel.AdjudicatorReq) error {
d, err := a.readState(ctx, req.Params.ID())
if err != nil {
return fmt.Errorf("reading state: %w", err)
}

s1, s2 := req.Tx.State, d.State.PerunState()
if s1.Equal(s2) != nil {
return fmt.Errorf("not equal: %v, %v", s1, s2)
}

fn := AdjudicatorMsgFunc(func(p channel.Params, _ channel.State, _ []wallet.Sig) ([]byte, error) {
return binding.NewConcludeDisputeMsgExecute(&p)
})
return a.callAdjudicator(ctx, fn, req)
}

func (a *Adjudicator) readState(ctx context.Context, ch channel.ID) (binding.DisputeQueryResponse, error) {
q, err := binding.NewDisputeQueryMsg(ch)
if err != nil {
return binding.DisputeQueryResponse{}, err
}

resp, err := a.Query(ctx, q)
if err != nil {
return binding.DisputeQueryResponse{}, err
}

return binding.DecodeDisputeQueryResponse(resp.Data)
}

func (a *Adjudicator) withdraw(ctx context.Context, req channel.AdjudicatorReq) error {
w := binding.NewWithdrawal(req.Params.ID(), req.Acc.Address(), a.Account())
b := w.Bytes()
Expand Down
11 changes: 0 additions & 11 deletions channel/binding/conclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,3 @@ func NewConcludeExecuteMsg(p channel.Params, s channel.State, sigs []wallet.Sig)
}
return json.Marshal(msg)
}

type ConcludeDisputeExecuteMsg struct {
ConcludeDispute Params `json:"conclude_dispute"`
}

func NewConcludeDisputeMsgExecute(p *channel.Params) ([]byte, error) {
msg := ConcludeDisputeExecuteMsg{
ConcludeDispute: makeParams(p),
}
return json.Marshal(msg)
}
Binary file modified channel/contract/perun_cosmwasm.wasm
Binary file not shown.
15 changes: 1 addition & 14 deletions channel/contract/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"additionalProperties": false
},
{
"description": "Collaboratively concludes a channel in one step.\n\nThis function concludes a channel in the case that all participants want to close it. Can only be called with a [State::finalized] state that is signed by all participants.",
"description": "Concludes a channel.\n\nExpects either a final state or the dispute period to be over.",
"type": "object",
"required": [
"conclude"
Expand Down Expand Up @@ -79,19 +79,6 @@
},
"additionalProperties": false
},
{
"description": "Concluded a disputed channel.\n\nCan only be called after the timeout of the dispute ran out or if a [State::finalized] state is provided and signed by all participants.",
"type": "object",
"required": [
"conclude_dispute"
],
"properties": {
"conclude_dispute": {
"$ref": "#/definitions/Params"
}
},
"additionalProperties": false
},
{
"description": "Withdraws funds from a concluded channel.\n\nCan be called by each participant after a channel was concluded to withdraw his outcome of the channel. This is the counterpart to [ExecuteMsg::Deposit].",
"type": "object",
Expand Down
13 changes: 12 additions & 1 deletion channel/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ func (s *EventSubscription) Close() error {
}

func (s *EventSubscription) readState(ctx context.Context) (binding.DisputeQueryResponse, error) {
return s.adjudicator.readState(ctx, s.channelID)
ch := s.channelID
q, err := binding.NewDisputeQueryMsg(ch)
if err != nil {
return binding.DisputeQueryResponse{}, err
}

resp, err := s.adjudicator.Query(ctx, q)
if err != nil {
return binding.DisputeQueryResponse{}, err
}

return binding.DecodeDisputeQueryResponse(resp.Data)
}

func (s *EventSubscription) makeEvent(d binding.DisputeQueryResponse) channel.AdjudicatorEvent {
Expand Down

0 comments on commit 3fa5c35

Please sign in to comment.