Skip to content

Commit 86a48df

Browse files
authored
Remove channel id array (#2)
* chore: Update go-perun dependency and contract bindings fix(all): Adjust code to use singular channelID instead of map Signed-off-by: Sophia Koehler <sophia@perun.network> * fix: remove unwanted linters Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): Use named BackendID and update license date Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(channel): go fmt files Signed-off-by: Sophia Koehler <sophia@perun.network> * chore: Add comments Signed-off-by: Sophia Koehler <sophia@perun.network> * chore: Update go-perun dependency Signed-off-by: Sophia Koehler <sophia@perun.network> --------- Signed-off-by: Sophia Koehler <sophia@perun.network>
1 parent a30c3f0 commit 86a48df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+216
-228
lines changed

bindings/adjudicator/Adjudicator.go

+34-34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/adjudicator/AdjudicatorBinRuntime.go

+1-1
Large diffs are not rendered by default.

bindings/assetholdererc20/AssetHolderERC20.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/assetholdererc20/AssetHolderERC20BinRuntime.go

+1-1
Large diffs are not rendered by default.

bindings/assetholdereth/AssetHolderETH.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/assetholdereth/AssetHolderETHBinRuntime.go

+1-1
Large diffs are not rendered by default.

bindings/trivialapp/TrivialApp.go

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package trivialapp // import "github.com/perun-network/perun-eth-backend/bindings/trivialapp"
22

33
// TrivialAppBinRuntime is the runtime part of the compiled bytecode used for deploying new contracts.
4-
var TrivialAppBinRuntime = "6080604052348015600f57600080fd5b506004361060285760003560e01c806318dc6c0014602d575b600080fd5b603e60383660046057565b50505050565b005b600060a08284031215605157600080fd5b50919050565b60008060008060808587031215606c57600080fd5b843567ffffffffffffffff80821115608357600080fd5b9086019060c08289031215609657600080fd5b9094506020860135908082111560ab57600080fd5b60b5888389016040565b9450604087013591508082111560ca57600080fd5b5060d5878288016040565b94979396509394606001359350505056fea26469706673582212205081e797202cb035c07d4df0f6988f47b842ec24f720e8dc1336efef5813300764736f6c634300080f0033"
4+
var TrivialAppBinRuntime = "6080604052348015600f57600080fd5b506004361060285760003560e01c8063f7530b4114602d575b600080fd5b603e60383660046057565b50505050565b005b600060a08284031215605157600080fd5b50919050565b60008060008060808587031215606c57600080fd5b843567ffffffffffffffff80821115608357600080fd5b9086019060c08289031215609657600080fd5b9094506020860135908082111560ab57600080fd5b60b5888389016040565b9450604087013591508082111560ca57600080fd5b5060d5878288016040565b94979396509394606001359350505056fea26469706673582212202c476f6a190b843966fe8a555305f8b86806d95b0f98acb69ff55ebc59aa68cb64736f6c634300080f0033"

channel/adjudicator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func ValidateAdjudicator(ctx context.Context, backend bind.ContractCaller, adjud
189189
// toEthSubStates generates a channel tree in depth-first order.
190190
func toEthSubStates(state *channel.State, subStates channel.StateMap) (ethSubStates []adjudicator.ChannelState) {
191191
for _, subAlloc := range state.Locked {
192-
subState, ok := subStates[channel.IDKey(subAlloc.ID)]
192+
subState, ok := subStates[subAlloc.ID]
193193
if !ok {
194194
log.Panic("sub-state not found")
195195
}

channel/adjudicator_internal_test.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 - See NOTICE file for copyright holders.
1+
// Copyright 2024 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@ import (
1818
"math/rand"
1919
"testing"
2020

21+
"github.com/perun-network/perun-eth-backend/wallet"
22+
2123
"github.com/perun-network/perun-eth-backend/bindings/adjudicator"
2224
"github.com/stretchr/testify/assert"
2325
"perun.network/go-perun/channel"
@@ -38,13 +40,13 @@ func Test_toEthSubStates(t *testing.T) {
3840
{
3941
title: "nil map gives nil slice",
4042
setup: func() (state *channel.State, subStates channel.StateMap, expected []adjudicator.ChannelState) {
41-
return channeltest.NewRandomState(rng, channeltest.WithBackend(1)), nil, nil
43+
return channeltest.NewRandomState(rng, channeltest.WithBackend(wallet.BackendID)), nil, nil
4244
},
4345
},
4446
{
4547
title: "fresh map gives nil slice",
4648
setup: func() (state *channel.State, subStates channel.StateMap, expected []adjudicator.ChannelState) {
47-
return channeltest.NewRandomState(rng, channeltest.WithBackend(1)), nil, nil
49+
return channeltest.NewRandomState(rng, channeltest.WithBackend(wallet.BackendID)), nil, nil
4850
},
4951
},
5052
{
@@ -84,7 +86,7 @@ func Test_toEthSubStates(t *testing.T) {
8486
func genStates(rng *rand.Rand, n int) (states []*channel.State) {
8587
states = make([]*channel.State, n)
8688
for i := range states {
87-
states[i] = channeltest.NewRandomState(rng, channeltest.WithBackend(1))
89+
states[i] = channeltest.NewRandomState(rng, channeltest.WithBackend(wallet.BackendID))
8890
}
8991
return
9092
}

channel/adjudicator_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 - See NOTICE file for copyright holders.
1+
// Copyright 2024 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ func testSignState(t *testing.T, accounts []*keystore.Account, state *channel.St
4747
func signState(accounts []*keystore.Account, state *channel.State) (channel.Transaction, error) {
4848
sigs := make([][]byte, len(accounts))
4949
for i := range accounts {
50-
sig, err := channel.Sign(accounts[i], state, 1)
50+
sig, err := channel.Sign(accounts[i], state, ethwallettest.BackendID)
5151
if err != nil {
5252
return channel.Transaction{}, errors.WithMessagef(err, "signing with account %d", i)
5353
}
@@ -68,7 +68,7 @@ func TestSubscribeRegistered(t *testing.T) {
6868
rng,
6969
channeltest.WithChallengeDuration(uint64(100*time.Second)),
7070
channeltest.WithParts(s.Parts),
71-
channeltest.WithBackend(1),
71+
channeltest.WithBackend(ethwallettest.BackendID),
7272
channeltest.WithAssets(s.Asset),
7373
channeltest.WithIsFinal(false),
7474
channeltest.WithLedgerChannel(true),
@@ -94,7 +94,7 @@ func TestSubscribeRegistered(t *testing.T) {
9494
tx := testSignState(t, s.Accs, state)
9595
req := channel.AdjudicatorReq{
9696
Params: params,
97-
Acc: map[wallet.BackendID]wallet.Account{1: s.Accs[0]},
97+
Acc: map[wallet.BackendID]wallet.Account{ethwallettest.BackendID: s.Accs[0]},
9898
Idx: channel.Index(0),
9999
Tx: tx,
100100
}

channel/asset.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2024 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -49,12 +49,12 @@ func MakeChainID(id *big.Int) ChainID {
4949
return ChainID{id}
5050
}
5151

52-
// MakeAssetID makes a AssetID for the given id.
53-
func MakeAssetID(id *big.Int) multi.AssetID {
52+
// MakeLedgerBackendID makes a AssetID for the given id.
53+
func MakeLedgerBackendID(id *big.Int) multi.LedgerBackendID {
5454
if id.Sign() < 0 {
5555
panic("must not be smaller than zero")
5656
}
57-
return AssetID{backendID: 1, ledgerID: MakeChainID(id)}
57+
return AssetID{backendID: wallet.BackendID, ledgerID: MakeChainID(id)}
5858
}
5959

6060
// UnmarshalBinary unmarshals the chainID from its binary representation.
@@ -66,7 +66,7 @@ func (id *ChainID) UnmarshalBinary(data []byte) error {
6666
// MarshalBinary marshals the chainID into its binary representation.
6767
func (id ChainID) MarshalBinary() (data []byte, err error) {
6868
if id.Sign() == -1 {
69-
return nil, errors.New("cannot marshal negative AssetID")
69+
return nil, errors.New("cannot marshal negative LedgerBackendID")
7070
}
7171
return id.Bytes(), nil
7272
}
@@ -108,8 +108,8 @@ func (id AssetID) LedgerID() multi.LedgerID {
108108
return &id.ledgerID
109109
}
110110

111-
// AssetID returns the asset ID of the asset.
112-
func (a Asset) AssetID() multi.AssetID {
111+
// LedgerBackendID returns the asset ID of the asset.
112+
func (a Asset) LedgerBackendID() multi.LedgerBackendID {
113113
return a.assetID
114114
}
115115

@@ -141,12 +141,12 @@ func (a *Asset) UnmarshalBinary(data []byte) error {
141141

142142
// LedgerID returns the ledger ID the asset lives on.
143143
func (a Asset) LedgerID() multi.LedgerID {
144-
return a.AssetID().LedgerID()
144+
return a.LedgerBackendID().LedgerID()
145145
}
146146

147147
// NewAsset creates a new asset from an chainID and the AssetHolder address.
148148
func NewAsset(chainID *big.Int, assetHolder common.Address) *Asset {
149-
id := MakeAssetID(chainID).(AssetID) //nolint: forcetypeassert // AssetID implements multi.AssetID
149+
id := MakeLedgerBackendID(chainID).(AssetID) //nolint: forcetypeassert // LedgerBackendID implements multi.LedgerBackendID
150150
return &Asset{assetID: id, AssetHolder: *wallet.AsWalletAddr(assetHolder)}
151151
}
152152

channel/asset_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 - See NOTICE file for copyright holders.
1+
// Copyright 2024 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)