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

crypto.Address -> sdk.Address #545

Merged
merged 1 commit into from
Mar 2, 2018
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
4 changes: 2 additions & 2 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ func (tx testUpdatePowerTx) Get(key interface{}) (value interface{}) { return ni
func (tx testUpdatePowerTx) GetMsg() sdk.Msg { return tx }
func (tx testUpdatePowerTx) GetSignBytes() []byte { return nil }
func (tx testUpdatePowerTx) ValidateBasic() sdk.Error { return nil }
func (tx testUpdatePowerTx) GetSigners() []crypto.Address { return nil }
func (tx testUpdatePowerTx) GetFeePayer() crypto.Address { return nil }
func (tx testUpdatePowerTx) GetSigners() []sdk.Address { return nil }
func (tx testUpdatePowerTx) GetFeePayer() sdk.Address { return nil }
func (tx testUpdatePowerTx) GetSignatures() []sdk.StdSignature { return nil }

func TestValidatorChange(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Msg interface {
// Signers returns the addrs of signers that must sign.
// CONTRACT: All signatures must be present to be valid.
// CONTRACT: Returns addrs in some deterministic order.
GetSigners() []crypto.Address
GetSigners() []Address
}

```
Expand Down Expand Up @@ -75,24 +75,24 @@ type SendMsg struct {
}

type IssueMsg struct {
Banker crypto.Address `json:"banker"`
Banker sdk.Address `json:"banker"`
Outputs []Output `json:"outputs"`
}
```

Each specifies the addresses that must sign the message:

```golang
func (msg SendMsg) GetSigners() []crypto.Address {
addrs := make([]crypto.Address, len(msg.Inputs))
func (msg SendMsg) GetSigners() []sdk.Address {
addrs := make([]sdk.Address, len(msg.Inputs))
for i, in := range msg.Inputs {
addrs[i] = in.Address
}
return addrs
}

func (msg IssueMsg) GetSigners() []crypto.Address {
return []crypto.Address{msg.Banker}
func (msg IssueMsg) GetSigners() []sdk.Address {
return []sdk.Address{msg.Banker}
}
```

Expand All @@ -107,7 +107,7 @@ type Tx interface {

// The address that pays the base fee for this message. The fee is
// deducted before the Msg is processed.
GetFeePayer() crypto.Address
GetFeePayer() Address

// Get the canonical byte representation of the Tx.
// Includes any signatures (or empty slots).
Expand Down
14 changes: 7 additions & 7 deletions docs/sdk/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ implementing the ``Msg`` interface:
// Signers returns the addrs of signers that must sign.
// CONTRACT: All signatures must be present to be valid.
// CONTRACT: Returns addrs in some deterministic order.
GetSigners() []crypto.Address
GetSigners() []Address
}

Messages must specify their type via the ``Type()`` method. The type should
Expand Down Expand Up @@ -188,24 +188,24 @@ For instance, the ``Basecoin`` message types are defined in ``x/bank/tx.go``:
}

type IssueMsg struct {
Banker crypto.Address `json:"banker"`
Banker sdk.Address `json:"banker"`
Outputs []Output `json:"outputs"`
}

Each specifies the addresses that must sign the message:

::

func (msg SendMsg) GetSigners() []crypto.Address {
addrs := make([]crypto.Address, len(msg.Inputs))
func (msg SendMsg) GetSigners() []sdk.Address {
addrs := make([]sdk.Address, len(msg.Inputs))
for i, in := range msg.Inputs {
addrs[i] = in.Address
}
return addrs
}

func (msg IssueMsg) GetSigners() []crypto.Address {
return []crypto.Address{msg.Banker}
func (msg IssueMsg) GetSigners() []sdk.Address {
return []sdk.Address{msg.Banker}
}

Transactions
Expand All @@ -221,7 +221,7 @@ A transaction is a message with additional information for authentication:

// The address that pays the base fee for this message. The fee is
// deducted before the Msg is processed.
GetFeePayer() crypto.Address
GetFeePayer() Address

// Get the canonical byte representation of the Tx.
// Includes any signatures (or empty slots).
Expand Down
8 changes: 4 additions & 4 deletions examples/basecoin/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ func TestSendMsg(t *testing.T) {
var msg = bank.SendMsg{
Inputs: []bank.Input{
{
Address: crypto.Address([]byte("input")),
Address: sdk.Address([]byte("input")),
Coins: sdk.Coins{{"atom", 10}},
Sequence: 1,
},
},
Outputs: []bank.Output{
{
Address: crypto.Address([]byte("output")),
Address: sdk.Address([]byte("output")),
Coins: sdk.Coins{{"atom", 10}},
},
},
Expand Down Expand Up @@ -155,14 +155,14 @@ func TestSendMsgWithAccounts(t *testing.T) {
var msg = bank.SendMsg{
Inputs: []bank.Input{
{
Address: crypto.Address(addr1),
Address: sdk.Address(addr1),
Coins: sdk.Coins{{"foocoin", 10}},
Sequence: 1,
},
},
Outputs: []bank.Output{
{
Address: crypto.Address(addr2),
Address: sdk.Address(addr2),
Coins: sdk.Coins{{"foocoin", 10}},
},
},
Expand Down
7 changes: 3 additions & 4 deletions examples/basecoin/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
crypto "github.com/tendermint/go-crypto"
wire "github.com/tendermint/go-wire"
)

Expand Down Expand Up @@ -41,9 +40,9 @@ type GenesisState struct {

// GenesisAccount doesn't need pubkey or sequence
type GenesisAccount struct {
Name string `json:"name"`
Address crypto.Address `json:"address"`
Coins sdk.Coins `json:"coins"`
Name string `json:"name"`
Address sdk.Address `json:"address"`
Coins sdk.Coins `json:"coins"`
}

func NewGenesisAccount(aa *AppAccount) *GenesisAccount {
Expand Down
5 changes: 2 additions & 3 deletions examples/kvstore/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"

sdk "github.com/cosmos/cosmos-sdk/types"
crypto "github.com/tendermint/go-crypto"
)

// An sdk.Tx which is its own sdk.Msg.
Expand Down Expand Up @@ -44,15 +43,15 @@ func (tx kvstoreTx) ValidateBasic() sdk.Error {
return nil
}

func (tx kvstoreTx) GetSigners() []crypto.Address {
func (tx kvstoreTx) GetSigners() []sdk.Address {
return nil
}

func (tx kvstoreTx) GetSignatures() []sdk.StdSignature {
return nil
}

func (tx kvstoreTx) GetFeePayer() crypto.Address {
func (tx kvstoreTx) GetFeePayer() sdk.Address {
return nil
}

Expand Down
5 changes: 2 additions & 3 deletions mock/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
crypto "github.com/tendermint/go-crypto"
)

// An sdk.Tx which is its own sdk.Msg.
Expand Down Expand Up @@ -57,15 +56,15 @@ func (tx kvstoreTx) ValidateBasic() sdk.Error {
return nil
}

func (tx kvstoreTx) GetSigners() []crypto.Address {
func (tx kvstoreTx) GetSigners() []sdk.Address {
return nil
}

func (tx kvstoreTx) GetSignatures() []sdk.StdSignature {
return nil
}

func (tx kvstoreTx) GetFeePayer() crypto.Address {
func (tx kvstoreTx) GetFeePayer() sdk.Address {
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions server/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/spf13/cobra"

crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/go-crypto/keys"
"github.com/tendermint/go-crypto/keys/words"
cmn "github.com/tendermint/tmlibs/common"
Expand All @@ -17,6 +16,8 @@ import (
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
cfg "github.com/tendermint/tendermint/config"
tmtypes "github.com/tendermint/tendermint/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// InitCmd will initialize all files for tendermint,
Expand Down Expand Up @@ -45,7 +46,7 @@ type GenOptions func(args []string) (json.RawMessage, error)
// along with the secret phrase to recover the private key.
// You can give coins to this address and return the recovery
// phrase to the user to access them.
func GenerateCoinKey() (crypto.Address, string, error) {
func GenerateCoinKey() (sdk.Address, string, error) {
// construct an in-memory key store
codec, err := words.LoadCodec("english")
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package types

import (
crypto "github.com/tendermint/go-crypto"
cmn "github.com/tendermint/tmlibs/common"
)

type Address = cmn.HexBytes

// Account is a standard account using a sequence number for replay protection
// and a pubkey for authentication.
type Account interface {
GetAddress() crypto.Address
SetAddress(crypto.Address) error // errors if already set.
GetAddress() Address
SetAddress(Address) error // errors if already set.

GetPubKey() crypto.PubKey // can return nil.
SetPubKey(crypto.PubKey) error
Expand All @@ -26,8 +29,8 @@ type Account interface {
// AccountMapper stores and retrieves accounts from stores
// retrieved from the context.
type AccountMapper interface {
NewAccountWithAddress(ctx Context, addr crypto.Address) Account
GetAccount(ctx Context, addr crypto.Address) Account
NewAccountWithAddress(ctx Context, addr Address) Account
GetAccount(ctx Context, addr Address) Account
SetAccount(ctx Context, acc Account)
}

Expand Down
4 changes: 1 addition & 3 deletions types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package types
import (
"fmt"
"runtime"

"github.com/tendermint/go-crypto"
)

// ABCI Response Code
Expand Down Expand Up @@ -86,7 +84,7 @@ func ErrInsufficientFunds(msg string) Error {
func ErrUnknownRequest(msg string) Error {
return newError(CodeUnknownRequest, msg)
}
func ErrUnrecognizedAddress(addr crypto.Address) Error {
func ErrUnrecognizedAddress(addr Address) Error {
return newError(CodeUnrecognizedAddress, addr.String())
}
func ErrInvalidSequence(msg string) Error {
Expand Down
10 changes: 3 additions & 7 deletions types/tx_msg.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package types

import (
crypto "github.com/tendermint/go-crypto"
)

// Transactions messages must fulfill the Msg
type Msg interface {

Expand All @@ -24,7 +20,7 @@ type Msg interface {
// Signers returns the addrs of signers that must sign.
// CONTRACT: All signatures must be present to be valid.
// CONTRACT: Returns addrs in some deterministic order.
GetSigners() []crypto.Address
GetSigners() []Address
}

// Transactions objects must fulfill the Tx
Expand All @@ -35,7 +31,7 @@ type Tx interface {

// The address that pays the base fee for this message. The fee is
// deducted before the Msg is processed.
GetFeePayer() crypto.Address
GetFeePayer() Address

// Signatures returns the signature of signers who signed the Msg.
// CONTRACT: Length returned is same as length of
Expand Down Expand Up @@ -65,7 +61,7 @@ func NewStdTx(msg Msg, sigs []StdSignature) StdTx {

//nolint
func (tx StdTx) GetMsg() Msg { return tx.Msg }
func (tx StdTx) GetFeePayer() crypto.Address { return tx.Signatures[0].PubKey.Address() } // XXX but PubKey is optional!
func (tx StdTx) GetFeePayer() Address { return tx.Signatures[0].PubKey.Address() } // XXX but PubKey is optional!
func (tx StdTx) GetSignatures() []StdSignature { return tx.Signatures }

//-------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions x/auth/baseaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ var _ sdk.Account = (*BaseAccount)(nil)
// Extend this by embedding this in your AppAccount.
// See the examples/basecoin/types/account.go for an example.
type BaseAccount struct {
Address crypto.Address `json:"address"`
Address sdk.Address `json:"address"`
Coins sdk.Coins `json:"coins"`
PubKey crypto.PubKey `json:"public_key"`
Sequence int64 `json:"sequence"`
}

func NewBaseAccountWithAddress(addr crypto.Address) BaseAccount {
func NewBaseAccountWithAddress(addr sdk.Address) BaseAccount {
return BaseAccount{
Address: addr,
}
Expand All @@ -40,12 +40,12 @@ func (acc *BaseAccount) Set(key interface{}, value interface{}) error {
}

// Implements sdk.Account.
func (acc BaseAccount) GetAddress() crypto.Address {
func (acc BaseAccount) GetAddress() sdk.Address {
return acc.Address
}

// Implements sdk.Account.
func (acc *BaseAccount) SetAddress(addr crypto.Address) error {
func (acc *BaseAccount) SetAddress(addr sdk.Address) error {
if len(acc.Address) != 0 {
return errors.New("cannot override BaseAccount address")
}
Expand Down
3 changes: 1 addition & 2 deletions x/auth/commands/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"

crypto "github.com/tendermint/go-crypto"
wire "github.com/tendermint/go-wire"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -61,7 +60,7 @@ func (c commander) getAccountCmd(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
key := crypto.Address(bz)
key := sdk.Address(bz)

res, err := client.Query(key, c.storeName)

Expand Down
5 changes: 2 additions & 3 deletions x/auth/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"reflect"

crypto "github.com/tendermint/go-crypto"
wire "github.com/tendermint/go-wire"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -66,14 +65,14 @@ func (am accountMapper) Seal() sealedAccountMapper {
}

// Implements sdk.AccountMapper.
func (am accountMapper) NewAccountWithAddress(ctx sdk.Context, addr crypto.Address) sdk.Account {
func (am accountMapper) NewAccountWithAddress(ctx sdk.Context, addr sdk.Address) sdk.Account {
acc := am.clonePrototype()
acc.SetAddress(addr)
return acc
}

// Implements sdk.AccountMapper.
func (am accountMapper) GetAccount(ctx sdk.Context, addr crypto.Address) sdk.Account {
func (am accountMapper) GetAccount(ctx sdk.Context, addr sdk.Address) sdk.Account {
store := ctx.KVStore(am.key)
bz := store.Get(addr)
if bz == nil {
Expand Down
Loading