Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚚 [MIGRATION] Use pkg/io instead of poly-go/io #271

Merged
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/ethereum/channel/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
ethwallettest "perun.network/go-perun/backend/ethereum/wallet/test"
perunchannel "perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
iotest "perun.network/go-perun/pkg/io/test"
perunwallet "perun.network/go-perun/wallet"
wallettest "perun.network/go-perun/wallet/test"
iotest "polycry.pt/poly-go/io/test"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down
2 changes: 1 addition & 1 deletion backend/ethereum/wallet/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/pkg/errors"

perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
perunio "polycry.pt/poly-go/io"
)

// Backend implements the utility interface defined in the wallet package.
Expand Down
2 changes: 1 addition & 1 deletion backend/sim/channel/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"math/rand"

"perun.network/go-perun/channel"
perunio "polycry.pt/poly-go/io"
perunio "perun.network/go-perun/pkg/io"
)

// Asset simulates a `channel.Asset` by only containing an `ID`.
Expand Down
2 changes: 1 addition & 1 deletion backend/sim/channel/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/log"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
perunio "polycry.pt/poly-go/io"
)

// backend implements the utility interface defined in the channel package.
Expand Down
2 changes: 1 addition & 1 deletion backend/sim/wallet/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"github.com/pkg/errors"

"perun.network/go-perun/log"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
perunio "polycry.pt/poly-go/io"
)

// Address represents a simulated address.
Expand Down
2 changes: 1 addition & 1 deletion backend/sim/wallet/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/pkg/errors"

"perun.network/go-perun/log"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
perunio "polycry.pt/poly-go/io"
)

var curve = elliptic.P256()
Expand Down
2 changes: 1 addition & 1 deletion channel/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"log"
"math/big"

perunio "polycry.pt/poly-go/io"
perunio "perun.network/go-perun/pkg/io"
perunbig "polycry.pt/poly-go/math/big"

"github.com/ethereum/go-ethereum/accounts/abi"
Expand Down
4 changes: 2 additions & 2 deletions channel/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
perunio "polycry.pt/poly-go/io"
iotest "polycry.pt/poly-go/io/test"
perunio "perun.network/go-perun/pkg/io"
iotest "perun.network/go-perun/pkg/io/test"
pkgbig "polycry.pt/poly-go/math/big"
pkgtest "polycry.pt/poly-go/test"
)
Expand Down
2 changes: 1 addition & 1 deletion channel/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"github.com/pkg/errors"

perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
perunio "polycry.pt/poly-go/io"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion channel/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"github.com/pkg/errors"

"perun.network/go-perun/log"
"perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"polycry.pt/poly-go/io"
"polycry.pt/poly-go/math/big"
)

Expand Down
2 changes: 1 addition & 1 deletion channel/mock_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"github.com/pkg/errors"

perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
perunio "polycry.pt/poly-go/io"
)

// MockApp a mocked App whose behaviour is determined by the MockOp passed to it either as State.Data or Action.
Expand Down
2 changes: 1 addition & 1 deletion channel/mock_app_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"github.com/stretchr/testify/assert"

iotest "perun.network/go-perun/pkg/io/test"
wallettest "perun.network/go-perun/wallet/test"
iotest "polycry.pt/poly-go/io/test"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down
2 changes: 1 addition & 1 deletion channel/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/pkg/errors"

"perun.network/go-perun/log"
"perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"polycry.pt/poly-go/io"
)

// IDLen the length of a channelID.
Expand Down
4 changes: 2 additions & 2 deletions channel/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
"polycry.pt/poly-go/io"
iotest "polycry.pt/poly-go/io/test"
"perun.network/go-perun/pkg/io"
iotest "perun.network/go-perun/pkg/io/test"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down
2 changes: 1 addition & 1 deletion channel/persistence/keyvalue/persistedstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"io"

"perun.network/go-perun/channel"
perunio "polycry.pt/poly-go/io"
perunio "perun.network/go-perun/pkg/io"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion channel/persistence/keyvalue/persister.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/pkg/errors"

"perun.network/go-perun/channel"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wire"
perunio "polycry.pt/poly-go/io"
"polycry.pt/poly-go/sortedkv"
)

Expand Down
2 changes: 1 addition & 1 deletion channel/persistence/keyvalue/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/channel/persistence"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire"
perunio "polycry.pt/poly-go/io"
"polycry.pt/poly-go/sortedkv"
)

Expand Down
2 changes: 1 addition & 1 deletion channel/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/pkg/errors"

perunio "polycry.pt/poly-go/io"
perunio "perun.network/go-perun/pkg/io"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion channel/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
_ "perun.network/go-perun/backend/sim" // backend init
"perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
iotest "polycry.pt/poly-go/io/test"
iotest "perun.network/go-perun/pkg/io/test"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down
2 changes: 1 addition & 1 deletion channel/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"github.com/pkg/errors"

perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
perunio "polycry.pt/poly-go/io"
)

// Transaction is a channel state together with valid signatures from the
Expand Down
2 changes: 1 addition & 1 deletion channel/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
iotest "polycry.pt/poly-go/io/test"
iotest "perun.network/go-perun/pkg/io/test"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down
2 changes: 1 addition & 1 deletion client/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/log"
"perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire"
pcontext "polycry.pt/poly-go/context"
"polycry.pt/poly-go/io"
"polycry.pt/poly-go/sync/atomic"
)

Expand Down
2 changes: 1 addition & 1 deletion client/proposalmsgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/log"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire"
perunio "polycry.pt/poly-go/io"
perunbig "polycry.pt/poly-go/math/big"
)

Expand Down
2 changes: 1 addition & 1 deletion client/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/pkg/errors"
"perun.network/go-perun/channel"
perunio "polycry.pt/poly-go/io"
perunio "perun.network/go-perun/pkg/io"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion client/syncmsgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"io"

"perun.network/go-perun/channel"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wire"
perunio "polycry.pt/poly-go/io"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion client/test/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/log"
"perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"polycry.pt/poly-go/io"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion client/updatemsgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"io"

"perun.network/go-perun/channel"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire"
perunio "polycry.pt/poly-go/io"
)

func init() {
Expand Down
86 changes: 86 additions & 0 deletions pkg/io/bigint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2019 - 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 io

import (
"io"
"math/big"

"github.com/pkg/errors"
)

// MaxBigIntLength defines the maximum length of a big integer.
// 1024bit -> 128 bytes.
const MaxBigIntLength = 128

// BigInt is a serializer big integer.
type BigInt struct {
*big.Int
}

// Decode reads a big.Int from the given stream.
func (b *BigInt) Decode(reader io.Reader) error {
// Read length
lengthData := make([]byte, 1)
if _, err := reader.Read(lengthData); err != nil {
return errors.Wrap(err, "failed to decode length of big.Int")
}

length := lengthData[0]
if length > MaxBigIntLength {
return errors.New("big.Int too big to decode")
}

bytes := make([]byte, length)
if n, err := io.ReadFull(reader, bytes); err != nil {
return errors.Wrapf(err, "failed to read bytes for big.Int, read %d/%d", n, length)
}

if b.Int == nil {
b.Int = new(big.Int)
}
b.Int.SetBytes(bytes)
return nil
}

// Encode writes a big.Int to the stream.
func (b BigInt) Encode(writer io.Writer) error {
if b.Int == nil {
panic("logic error: tried to encode nil big.Int")
}
if b.Int.Sign() == -1 {
panic("encoding of negative big.Int not implemented")
}

bytes := b.Bytes()
length := len(bytes)
// we serialize the length as uint8
if length > MaxBigIntLength {
return errors.New("big.Int too big to encode")
}

// Write length
if _, err := writer.Write([]byte{uint8(length)}); err != nil {
return errors.Wrap(err, "failed to write length")
}

if length == 0 {
return nil
}

// Write bytes
n, err := writer.Write(bytes)
return errors.Wrapf(err, "failed to write big.Int, wrote %d bytes of %d", n, length)
}
Loading