-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from perun-network/fix-for-goperun-0.10.7
Restore compatibility between go-perun post-0.10.6 and eth-backend
- Loading branch information
Showing
12 changed files
with
134 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// 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" | ||
|
||
ethwallet "github.com/perun-network/perun-eth-backend/wallet" | ||
ethtestwallet "github.com/perun-network/perun-eth-backend/wallet/test" | ||
"perun.network/go-perun/channel" | ||
) | ||
|
||
var _ channel.AppID = new(AppID) | ||
|
||
// AppID described an app identifier. | ||
type AppID struct { | ||
*ethwallet.Address | ||
} | ||
|
||
// AppIDKey is the key representation of an app identifier. | ||
type AppIDKey string | ||
|
||
// Equal compares two AppID objects for equality. | ||
func (a AppID) Equal(b channel.AppID) bool { | ||
bTyped, ok := b.(*AppID) | ||
if !ok { | ||
return false | ||
} | ||
return a.Address.Equal(bTyped.Address) | ||
} | ||
|
||
// Key returns the key representation of this app identifier. | ||
func (a AppID) Key() channel.AppIDKey { | ||
b, err := a.MarshalBinary() | ||
if err != nil { | ||
panic(err) | ||
} | ||
return channel.AppIDKey(b) | ||
} | ||
|
||
// MarshalBinary marshals the contents of AppID into a byte string. | ||
func (a AppID) MarshalBinary() ([]byte, error) { | ||
data, err := a.Address.MarshalBinary() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return data, nil | ||
} | ||
|
||
// UnmarshalBinary converts a bytestring, representing AppID into the AppID struct. | ||
func (a *AppID) UnmarshalBinary(data []byte) error { | ||
addr := ðwallet.Address{} | ||
err := addr.UnmarshalBinary(data) | ||
if err != nil { | ||
return err | ||
} | ||
appaddr := &AppID{addr} | ||
*a = *appaddr | ||
return nil | ||
} | ||
|
||
// NewRandomAppID calls NewRandomAddress to generate a random Ethereum test address. | ||
func NewRandomAppID(rng *rand.Rand) *AppID { | ||
addr := ethtestwallet.NewRandomAddress(rng) | ||
return &AppID{&addr} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters