Skip to content

Commit

Permalink
Merge pull request #15 from perun-network:chore-updateto-goperun_v0.11.0
Browse files Browse the repository at this point in the history
Update to go-perun v0.11.0 release
  • Loading branch information
iljabvh committed May 2, 2024
2 parents 39bead0 + 19e4db8 commit 39e8a08
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 4 deletions.
73 changes: 73 additions & 0 deletions channel/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2024 - See NOTICE file for copyright holders.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package channel

import (
"math/rand"

"perun.network/go-perun/channel"
"perun.network/go-perun/wallet"

stwallet "perun.network/perun-stellar-backend/wallet"
types "perun.network/perun-stellar-backend/wallet/types"
)

var _ channel.AppID = new(AppID)

type AppID struct {
wallet.Address
}

type AppIDKey string

func (a AppID) Equal(b channel.AppID) bool {
bTyped, ok := b.(*AppID)
if !ok {
return false
}
return a.Address.Equal(bTyped.Address)
}

func (a AppID) Key() channel.AppIDKey {
b, err := a.MarshalBinary()
if err != nil {
panic(err)
}
return channel.AppIDKey(b)
}

func (a AppID) MarshalBinary() ([]byte, error) {
data, err := a.Address.MarshalBinary()
if err != nil {
return nil, err
}
return data, nil
}

func (a *AppID) UnmarshalBinary(data []byte) error {
addr := &types.Address{}
err := addr.UnmarshalBinary(data)
if err != nil {
return err
}
appaddr := &AppID{addr}
*a = *appaddr
return nil
}

func NewRandomAppID(rng *rand.Rand) *AppID {
addr := stwallet.NewRandomAddress(rng)
return &AppID{addr}
}
8 changes: 7 additions & 1 deletion channel/backend.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 PolyCrypt GmbH
// Copyright 2024 PolyCrypt GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ import (
"perun.network/go-perun/channel"
"perun.network/go-perun/wallet"
"perun.network/perun-stellar-backend/channel/types"
wtypes "perun.network/perun-stellar-backend/wallet/types"
"perun.network/perun-stellar-backend/wire"
)

Expand Down Expand Up @@ -66,3 +67,8 @@ func EncodeState(state *channel.State) ([]byte, error) {
}
return ws.MarshalBinary()
}

func (b backend) NewAppID() channel.AppID {
addr := &wtypes.Address{}
return &AppID{addr}
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/creachadair/jrpc2 v1.1.0
github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2
github.com/stretchr/testify v1.8.4
perun.network/go-perun v0.10.6
perun.network/go-perun v0.11.0
polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37
)

Expand All @@ -17,6 +17,7 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-chi/chi v4.1.2+incompatible // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/schema v1.2.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/manucorporat/sse v0.0.0-20160126180136-ee05b128a739 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5 h1:oERTZ1buOUYlpmKaqlO5fYmz8cZ1rYu5DieJzF4ZVmU=
github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/imkira/go-interpol v1.1.0 h1:KIiKr0VSG2CUW1hl1jpiyuzuJeKUUpC8iM1AIE7N1Vk=
Expand Down Expand Up @@ -94,6 +96,8 @@ github.com/yudai/gojsondiff v0.0.0-20170107030110-7b1b7adf999d h1:yJIizrfO599ot2
github.com/yudai/gojsondiff v0.0.0-20170107030110-7b1b7adf999d/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
github.com/yudai/golcs v0.0.0-20150405163532-d1c525dea8ce h1:888GrqRxabUce7lj4OaoShPxodm3kXOMpSa85wdYzfY=
github.com/yudai/golcs v0.0.0-20150405163532-d1c525dea8ce/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
Expand All @@ -117,7 +121,7 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
perun.network/go-perun v0.10.6 h1:uj1e33yfCSfE75DK/uwjNp+TwvGG85Qhi6HuYQ9EPrQ=
perun.network/go-perun v0.10.6/go.mod h1:BGBZC3npkX457u87pjDd0NEIXr1a4dsH4H/YpLdGGe8=
perun.network/go-perun v0.11.0 h1:25aL0MsyXQ2rHziOnMwJMe70K6NTCbopZMwX67qxt/k=
perun.network/go-perun v0.11.0/go.mod h1:pY/1pJ2OMlCQgEbnfGh9wVfRMJtqN0iAKsiJBLH0/Gc=
polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37 h1:iA5GzEa/hHfVlQpimEjPV09NATwHXxSjWNB0VVodtew=
polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37/go.mod h1:XUBrNtqgEhN3EEOP/5gh7IBd3xVHKidCjXDZfl9+kMU=
44 changes: 44 additions & 0 deletions wallet/types/appid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2024 - See NOTICE file for copyright holders.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package types

import (
"github.com/stellar/go/keypair"
"perun.network/go-perun/wallet"
)

type Address keypair.FromAddress

var _ wallet.Address = (*Address)(nil)

func (a *Address) Equal(addr wallet.Address) bool {
other, ok := addr.(*Address)
if !ok {
return false
}
return (*keypair.FromAddress)(a).Equal((*keypair.FromAddress)(other))
}

func (a *Address) MarshalBinary() ([]byte, error) {
return (*keypair.FromAddress)(a).MarshalBinary()
}

func (a *Address) UnmarshalBinary(data []byte) error {
return (*keypair.FromAddress)(a).UnmarshalBinary(data)
}

func (a *Address) String() string {
return (*keypair.FromAddress)(a).Address()
}

0 comments on commit 39e8a08

Please sign in to comment.