From 86c68e51b9c84bbc07bee41e83035909ea271b43 Mon Sep 17 00:00:00 2001 From: Hagar Meir Date: Mon, 19 Sep 2022 15:25:39 +0300 Subject: [PATCH 1/2] review htlc terms Signed-off-by: Hagar Meir --- go.mod | 2 ++ go.sum | 2 ++ integration/token/interop/views/htlc/exchange.go | 2 +- token/services/interop/htlc/distribute.go | 15 ++++++++++++++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 528e3c0b5..206c9eafd 100755 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index da1830f1b..494dc22f2 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/integration/token/interop/views/htlc/exchange.go b/integration/token/interop/views/htlc/exchange.go index c9c7137b6..effbb3e35 100644 --- a/integration/token/interop/views/htlc/exchange.go +++ b/integration/token/interop/views/htlc/exchange.go @@ -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 diff --git a/token/services/interop/htlc/distribute.go b/token/services/interop/htlc/distribute.go index 31d0fd524..30c43fca6 100644 --- a/token/services/interop/htlc/distribute.go +++ b/token/services/interop/htlc/distribute.go @@ -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 { + 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 @@ -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 } From df38dabe839f31022017208eea1c7882ed4bd1ec Mon Sep 17 00:00:00 2001 From: Hagar Meir Date: Wed, 21 Sep 2022 09:26:28 +0300 Subject: [PATCH 2/2] fixup! review htlc terms Signed-off-by: Hagar Meir --- integration/token/interop/views/htlc/exchange.go | 2 +- token/services/interop/htlc/distribute.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration/token/interop/views/htlc/exchange.go b/integration/token/interop/views/htlc/exchange.go index effbb3e35..4b4a79707 100644 --- a/integration/token/interop/views/htlc/exchange.go +++ b/integration/token/interop/views/htlc/exchange.go @@ -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") - assert.NoError(terms.Review(), "failed reviewing terms") + assert.NoError(terms.Validate(), "failed to validate the terms") // Initiator's Leg var script *htlc.Script diff --git a/token/services/interop/htlc/distribute.go b/token/services/interop/htlc/distribute.go index 30c43fca6..418fc9974 100644 --- a/token/services/interop/htlc/distribute.go +++ b/token/services/interop/htlc/distribute.go @@ -37,8 +37,8 @@ func (t *Terms) FromBytes(raw []byte) error { return json.Unmarshal(raw, t) } -// Review checks the terms -func (t *Terms) Review() error { +// Validate checks the terms +func (t *Terms) Validate() error { if t.ReclamationDeadline <= 0 { return errors.New("reclamation deadline should be larger than zero") }