forked from hyperledger-labs/go-perun
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create app id type (hyperledger-labs#378)
* Create app id type Signed-off-by: Matthias Geihs <[email protected]> * Lint Signed-off-by: Matthias Geihs <[email protected]> * Payment App: Rename Addr to ID Signed-off-by: Matthias Geihs <[email protected]> * appID.Key: Remove comment Signed-off-by: Matthias Geihs <[email protected]> Signed-off-by: Matthias Geihs <[email protected]>
- Loading branch information
1 parent
be6e072
commit c23f66b
Showing
24 changed files
with
193 additions
and
67 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2022 - 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/backend/sim/wallet" | ||
"perun.network/go-perun/channel" | ||
) | ||
|
||
// AppID represents an app identifier. | ||
type AppID struct { | ||
*wallet.Address | ||
} | ||
|
||
// Equal returns whether the object is equal to the given object. | ||
func (id AppID) Equal(b channel.AppID) bool { | ||
bTyped, ok := b.(AppID) | ||
if !ok { | ||
return false | ||
} | ||
|
||
return id.Address.Equal(bTyped.Address) | ||
} | ||
|
||
// Key returns the key representation of this app identifier. | ||
func (id AppID) Key() channel.AppIDKey { | ||
b, err := id.MarshalBinary() | ||
if err != nil { | ||
panic(err) | ||
} | ||
return channel.AppIDKey(b) | ||
} | ||
|
||
// NewRandomAppID generates a new random app identifier. | ||
func NewRandomAppID(rng *rand.Rand) AppID { | ||
addr := wallet.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
Oops, something went wrong.