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

review htlc terms #382

Merged
merged 2 commits into from
Sep 21, 2022
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ require (
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huin/goupnp v1.0.0 // indirect
github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go v1.2.3-alpha.1 // indirect
github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-sdk v1.2.3-alpha.1.0.20210812140206-37f430515b8c // indirect
github.com/hyperledger/fabric-amcl v0.0.0-20210603140002-2670f91851c8 // indirect
github.com/hyperledger/fabric-config v0.1.0 // indirect
github.com/hyperledger/fabric-lib-go v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,9 @@ github.com/hyperledger-labs/orion-sdk-go v0.2.5 h1:HFGRTuMZgzo9EtyJeFAhVSlbrj6x3
github.com/hyperledger-labs/orion-sdk-go v0.2.5/go.mod h1:At8hiFATfkDXQ4AFLVbaTiC9GDhVDo8aN/supb1KBb4=
github.com/hyperledger-labs/orion-server v0.2.5 h1:aFudmB9SAnsT5v8jhazkuszEu0pdJNFqaYZF2GpvAuI=
github.com/hyperledger-labs/orion-server v0.2.5/go.mod h1:8kXVAU1wvFYGbFL1qmXwMi2i8gKV2smOdp1F1kq0HMk=
github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go v1.2.3-alpha.1 h1:vBvo0PNm82ht7wpBjlYY4ZHxV3YprCfdVd3T4JG9vBw=
github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go v1.2.3-alpha.1/go.mod h1:POCGO/RK9YDfgdhuyqjoD9tRNtWfK7Rh5AYYmsb1Chc=
github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-sdk v1.2.3-alpha.1.0.20210812140206-37f430515b8c h1:pKr8VnHlduEgdInwLWykYAw+lpUizjQJaJ8I5fVoRUo=
github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-sdk v1.2.3-alpha.1.0.20210812140206-37f430515b8c/go.mod h1:si2XAWZclHXC359OyYMpNHfonf2P7P2nzABdCA8mPqs=
github.com/hyperledger/fabric v1.4.0-rc1.0.20210722174351-9815a7a8f0f7 h1:LKWVg/yHT1GdNrcmnwp+Fzij8Wlwl7T7l22MP66TVNY=
github.com/hyperledger/fabric v1.4.0-rc1.0.20210722174351-9815a7a8f0f7/go.mod h1:g/IlXbV5x5GEprnavUFN+YoJZeIjwDocRcmO5ZG4ugc=
Expand Down
2 changes: 1 addition & 1 deletion integration/token/interop/views/htlc/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (v *FastExchangeResponderView) Call(context view.Context) (interface{}, err
terms, err := htlc.ReceiveTerms(context)
assert.NoError(err, "failed to receive the terms")

// TODO: validate the terms and tell the initiator if they are accepted
assert.NoError(terms.Review(), "failed reviewing terms")

// Initiator's Leg
var script *htlc.Script
Expand Down
15 changes: 14 additions & 1 deletion token/services/interop/htlc/distribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ func (t *Terms) FromBytes(raw []byte) error {
return json.Unmarshal(raw, t)
}

// Review checks the terms
func (t *Terms) Review() error {
HagarMeir marked this conversation as resolved.
Show resolved Hide resolved
if t.ReclamationDeadline <= 0 {
return errors.New("reclamation deadline should be larger than zero")
}
if t.Type1 == "" || t.Type2 == "" {
return errors.New("types should be set")
}
if t.Amount1 <= 0 || t.Amount2 <= 0 {
return errors.New("amounts should be larger than zero")
}
return nil
}

// DistributeTermsView holds the terms and the recipient identity to be used by the view
type DistributeTermsView struct {
recipient view.Identity
Expand Down Expand Up @@ -87,6 +101,5 @@ func (v *termsReceiverView) Call(context view.Context) (interface{}, error) {
if err := terms.FromBytes(payload); err != nil {
return nil, errors.Wrapf(err, "failed unmarshalling terms")
}
// TODO review terms and accept
return terms, nil
}