Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
57 changes: 57 additions & 0 deletions .github/workflows/ci-archived.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Archived Examples CI
on:
workflow_dispatch:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test-examples:
name: Test Examples
runs-on: ubuntu-latest
env:
ganache-image: trufflesuite/ganache-cli:v6.12.2

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.23'
- run: go version

- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Pull ganache-cli image
run: docker pull ${{ env.ganache-image }}

- name: Simple Client
working-directory: archived/simple-client
env:
MNEMONIC: pistol kiwi shrug future ozone ostrich match remove crucial oblige cream critic
run: |
docker run --rm --name ganache --detach --publish 8545:8545 ${{ env.ganache-image }} -b 5 -a 2 -m "$MNEMONIC"
sleep 5
go run .
docker stop ganache

- name: Collateralized Channels
working-directory: archived/collateralized-channels
env:
GANACHE_CMD: "docker run --name ganache --rm --publish 8545:8545 ${{ env.ganache-image }}"
run: |
docker stop ganache || true # Cleanup any previous instance

go test -v -timeout 60s .
docker stop ganache || true


14 changes: 2 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,10 @@ jobs:

- uses: dfinity/setup-dfx@main
with:
dfx-version: 0.15.0
dfx-version: 0.25.1

- name: Pull ganache-cli image
run: docker pull ${{ env.ganache-image }}

- name: Simple Client
working-directory: simple-client
env:
MNEMONIC: pistol kiwi shrug future ozone ostrich match remove crucial oblige cream critic
run: |
docker run --rm --name ganache --detach --publish 8545:8545 ${{ env.ganache-image }} -b 5 -a 2 -m "$MNEMONIC"
sleep 5
go run .
docker stop ganache

- name: Payment Channel ETH
working-directory: payment-channel
Expand Down Expand Up @@ -116,7 +106,7 @@ jobs:
./stopdfx.sh || true # stop any running dfx
./startdeploy.sh

sleep 30
sleep 5
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Reducing the sleep from 30s to 5s may cause flaky CI runs if deployment takes longer. Consider a health check or a longer timeout.

Copilot uses AI. Check for mistakes.

go run ./

./stopdfx.sh || true
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ git submodule init
git submodule update
```

## Archived Examples
Examples that are no longer maintained or rely on outdated dependencies have been moved to the `/archived/` directory.

These are retained for reference only and are **not actively tested or supported**.

A dedicated workflow (`Archived Examples CI`) runs tests for these on-demand, but they are excluded from required checks.

## License

The source code in this repository is made available under the Apache License, Version 2.0.
Expand Down
13 changes: 13 additions & 0 deletions archived/collateralized-channels/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Collateralized Channels (Archived ⚠️)

## Dependencies
This example requires the [ganache-cli](https://github.com/trufflesuite/ganache-cli) `v6.12.2` and [go-perun](https://github.com/hyperledger-labs/go-perun) `v0.6.0` . Newer versions of the dependencies might not be compatible.
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README still references go-perun v0.6.0, but the example now uses v0.13.0. Please update the version requirement accordingly.

Suggested change
This example requires the [ganache-cli](https://github.com/trufflesuite/ganache-cli) `v6.12.2` and [go-perun](https://github.com/hyperledger-labs/go-perun) `v0.6.0` . Newer versions of the dependencies might not be compatible.
This example requires the [ganache-cli](https://github.com/trufflesuite/ganache-cli) `v6.12.2` and [go-perun](https://github.com/hyperledger-labs/go-perun) `v0.13.0` . Newer versions of the dependencies might not be compatible.

Copilot uses AI. Check for mistakes.


## Run the example

Install [ganache-cli](https://github.com/trufflesuite/ganache-cli) `v6.12.2` and run
```
go test -v perun.network/perun-collateralized-channels
```

The test starts a ganache-cli in the background. If the test does not shut down in order, make sure to kill the corresponding `node` process manually.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package app

import (
"io"
"math/big"

"github.com/pkg/errors"

Expand All @@ -41,21 +42,36 @@ func (a *CollateralApp) Def() wallet.Address {
return a.Addr
}

func (a *CollateralApp) String() string {
return "CollateralApp"
}

func (a *CollateralApp) NewData() channel.Data {
return &CollateralAppData{}
}

// DecodeData decodes the channel data.
func (a *CollateralApp) DecodeData(r io.Reader) (channel.Data, error) {
balances, err := readTupleInt256ArrayArray(r)
if err != nil {
return nil, errors.WithMessage(err, "reading (int256[][])")
}
return &CollateralAppData{balances: balances}, nil
return CollateralAppData{balances: balances}, nil
}

// CollateralAppData is the app data struct.
type CollateralAppData struct {
balances [][]*big.Int
}

// Encode encodes app data onto an io.Writer.
func (d CollateralAppData) Encode(w io.Writer) (err error) {
err = writeTupleInt256ArrayArray(w, d.balances)
return errors.WithMessage(err, "writing (int256[][])")
}

// Clone returns a deep copy of the app data.
func (d CollateralAppData) Clone() channel.Data {
balances := make([][]*big.Int, len(d.balances))
for i := range balances {
balances[i] = make([]*big.Int, len(d.balances[i]))
for j := range balances[i] {
balances[i][j] = new(big.Int).Set(d.balances[i][j])
}
}
return CollateralAppData{balances: balances}
}

// ValidTransition checks that the data of the `to` state is of type Invoice.
Expand All @@ -68,7 +84,7 @@ func (a *CollateralApp) ValidTransition(_ *channel.Params, _, to *channel.State,

// ValidInit checks that the initial state is valid.
func (a *CollateralApp) ValidInit(p *channel.Params, s *channel.State) error {
d, ok := s.Data.(*CollateralAppData)
d, ok := s.Data.(CollateralAppData)
if !ok {
return errors.New("failed to cast app data")
} else if len(d.balances) != len(s.Assets) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
ethwallet "github.com/perun-network/perun-eth-backend/wallet"
"github.com/pkg/errors"
ewallet "perun.network/go-perun/backend/ethereum/wallet"
"perun.network/go-perun/channel"
"perun.network/go-perun/wallet"
)

func (a *CollateralApp) ZeroBalance() channel.Data {
return &CollateralAppData{
return CollateralAppData{
[][]*big.Int{{big.NewInt(0), big.NewInt(0)}},
}
}
Expand All @@ -51,7 +51,7 @@ func Transfer(peers []wallet.Address, s *channel.State, from common.Address, to
return errors.Errorf("unknown address: %v", from)
}

d, ok := s.Data.(*CollateralAppData)
d, ok := s.Data.(CollateralAppData)
if !ok {
return errors.New("invalid type")
}
Expand All @@ -64,7 +64,7 @@ func Transfer(peers []wallet.Address, s *channel.State, from common.Address, to
}

func ChannelBalance(peers []wallet.Address, data channel.Data, account common.Address) (*big.Int, error) {
d, ok := data.(*CollateralAppData)
d, ok := data.(CollateralAppData)
if !ok {
return nil, errors.New("invalid type")
}
Expand All @@ -84,9 +84,9 @@ func (d CollateralAppData) Balance(peers []wallet.Address, account common.Addres
}

func peerIndex(peers []wallet.Address, addr common.Address) (int, bool) {
walletAddr := ethwallet.AsWalletAddr(addr)
walletAddr := ewallet.AsWalletAddr(addr)
for i, p := range peers {
if p.Equal(walletAddr) {
if p.Cmp(walletAddr) == 0 {
return i, true
}
}
Expand Down
Loading
Loading