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

Waves address encoding and decoding. #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
*.test

# Outputs from tools
*.out
*.out
/.idea
40 changes: 40 additions & 0 deletions chain/waves/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package waves

import (
"github.com/renproject/multichain/api/address"
"github.com/wavesplatform/gowaves/pkg/proto"
)

type AddressDecoder struct{}

// NewAddressDecoder returns the default AddressDecoder for Waves chain. It
// uses the base58 alphabet to decode the string, and interprets the
// result as a 26-byte array.
func NewAddressDecoder() AddressDecoder {
return AddressDecoder{}
}

// DecodeAddress decodes from string into bytes.
func (AddressDecoder) DecodeAddress(encoded address.Address) (address.RawAddress, error) {
addr, err := proto.NewAddressFromString(string(encoded))
if err != nil {
return nil, err
}
return address.RawAddress(addr.Bytes()), nil
}

type AddressEncoder struct{}

// DecodeAddress decodes from bytes into string.
func (AddressEncoder) EncodeAddress(decoded address.RawAddress) (address.Address, error) {
addr, err := proto.NewAddressFromBytes(decoded)
if err != nil {
return "", err
}
return address.Address(addr.String()), nil
}

type AddressEncodeDecoder struct {
AddressDecoder
AddressEncoder
}
23 changes: 23 additions & 0 deletions chain/waves/address_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package waves

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/renproject/multichain/api/address"
)

var _ = Describe("Address", func() {
Context("when decoding and encoding", func() {
It("should equal itself", func() {
addr := address.Address("3PMtE788h78hf1DFVPPXKBVa58sjt3QLxwT")

dec, err := AddressEncodeDecoder{}.DecodeAddress(addr)
Expect(err).ToNot(HaveOccurred())

addr2, err := AddressEncodeDecoder{}.EncodeAddress(dec)
Expect(err).ToNot(HaveOccurred())

Expect(addr).Should(Equal(addr2))
})
})
})
1 change: 1 addition & 0 deletions chain/waves/waves.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package waves
13 changes: 13 additions & 0 deletions chain/waves/waves_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package waves_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestWaves(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Waves Suite")
}
32 changes: 12 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,24 @@ require (
github.com/btcsuite/btcd v0.20.1-beta
github.com/btcsuite/btcutil v1.0.2
github.com/codahale/blake2 v0.0.0-20150924215134-8d10d0420cbf
github.com/cosmos/cosmos-sdk v0.39.1
github.com/drand/drand v1.0.3-0.20200714175734-29705eaf09d4 // indirect
github.com/ethereum/go-ethereum v1.9.19
github.com/filecoin-project/go-address v0.0.3
github.com/filecoin-project/go-amt-ipld v0.0.0-20191205011053-79efc22d6cdc // indirect
github.com/filecoin-project/go-amt-ipld/v2 v2.1.0 // indirect
github.com/filecoin-project/go-bitfield v0.1.0 // indirect
github.com/filecoin-project/go-data-transfer v0.5.0 // indirect
github.com/filecoin-project/go-fil-markets v0.3.2 // indirect
github.com/filecoin-project/lotus v0.4.1
github.com/filecoin-project/sector-storage v0.0.0-20200723200950-ed2e57dde6df // indirect
github.com/filecoin-project/specs-actors v0.6.2-0.20200724193152-534b25bdca30
github.com/hannahhoward/cbor-gen-for v0.0.0-20200723175505-5892b522820a // indirect
github.com/ipfs/go-ds-badger2 v0.1.1-0.20200708190120-187fc06f714e // indirect
github.com/ipfs/go-hamt-ipld v0.1.1 // indirect
github.com/lib/pq v1.7.0 // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/kr/pretty v0.2.0 // indirect
github.com/mr-tron/base58 v1.1.3 // indirect
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.1
github.com/raulk/clock v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/renproject/id v0.4.2
github.com/renproject/pack v0.2.3
github.com/renproject/surge v1.2.5
github.com/tendermint/tendermint v0.33.8
github.com/terra-project/core v0.3.7
github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542 // indirect
github.com/stretchr/testify v1.6.1 // indirect
github.com/wavesplatform/gowaves v0.7.0
go.uber.org/zap v1.15.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect
golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20200608115520-7c474a2e3482 // indirect
google.golang.org/grpc v1.30.0 // indirect
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
)
Loading