asdf
This commit is contained in:
parent
e894fbe4b6
commit
50ed0fa1ae
|
@ -126,7 +126,7 @@ func (ctx CoreContext) GetFromAddress() (from sdk.Address, err error) {
|
|||
return nil, errors.Errorf("no key for: %s", name)
|
||||
}
|
||||
|
||||
return info.GetPubKey().Address(), nil
|
||||
return sdk.Address(info.GetPubKey().Address()), nil
|
||||
}
|
||||
|
||||
// sign and build the transaction from the msg
|
||||
|
|
|
@ -161,6 +161,12 @@ type NewKeyBody struct {
|
|||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// new key response REST body
|
||||
type NewKeyResponse struct {
|
||||
Address sdk.Address `json:"address"`
|
||||
Mnemonic string `json:"mnemonic"`
|
||||
}
|
||||
|
||||
// add new key REST handler
|
||||
func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var kb keys.Keybase
|
||||
|
@ -209,17 +215,11 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
|
|||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
keyOutput, err := Bech32KeyOutput(info)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
keyOutput.Seed = mnemonic
|
||||
|
||||
output, err := json.MarshalIndent(keyOutput, "", " ")
|
||||
address := sdk.Address(info.GetPubKey().Address().Bytes())
|
||||
bz, err := json.Marshal(NewKeyResponse{
|
||||
Address: address,
|
||||
Mnemonic: mnemonic,
|
||||
})
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
|
|
@ -50,7 +50,7 @@ func SetKeyBase(kb keys.Keybase) {
|
|||
type KeyOutput struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Address string `json:"address"`
|
||||
Address sdk.Address `json:"address"`
|
||||
PubKey string `json:"pub_key"`
|
||||
Seed string `json:"seed,omitempty"`
|
||||
}
|
||||
|
@ -70,10 +70,7 @@ func Bech32KeysOutput(infos []keys.Info) ([]KeyOutput, error) {
|
|||
|
||||
// create a KeyOutput in bech32 format
|
||||
func Bech32KeyOutput(info keys.Info) (KeyOutput, error) {
|
||||
bechAccount, err := sdk.Bech32ifyAcc(sdk.Address(info.GetPubKey().Address().Bytes()))
|
||||
if err != nil {
|
||||
return KeyOutput{}, err
|
||||
}
|
||||
account := sdk.Address(info.GetPubKey().Address().Bytes())
|
||||
bechPubKey, err := sdk.Bech32ifyAccPub(info.GetPubKey())
|
||||
if err != nil {
|
||||
return KeyOutput{}, err
|
||||
|
@ -81,7 +78,7 @@ func Bech32KeyOutput(info keys.Info) (KeyOutput, error) {
|
|||
return KeyOutput{
|
||||
Name: info.GetName(),
|
||||
Type: info.GetType(),
|
||||
Address: bechAccount,
|
||||
Address: account,
|
||||
PubKey: bechPubKey,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ func TestKeys(t *testing.T) {
|
|||
err = wire.Cdc.UnmarshalJSON([]byte(body), &resp)
|
||||
require.Nil(t, err, body)
|
||||
|
||||
addr2Bech32 := resp.Address
|
||||
addr2Bech32 := resp.Address.String()
|
||||
_, err = sdk.GetAccAddressBech32(addr2Bech32)
|
||||
require.NoError(t, err, "Failed to return a correct bech32 address")
|
||||
|
||||
|
@ -71,7 +71,7 @@ func TestKeys(t *testing.T) {
|
|||
err = cdc.UnmarshalJSON([]byte(body), &m)
|
||||
require.Nil(t, err)
|
||||
|
||||
addrBech32 := sdk.MustBech32ifyAcc(addr)
|
||||
addrBech32 := addr.String()
|
||||
|
||||
require.Equal(t, name, m[0].Name, "Did not serve keys name correctly")
|
||||
require.Equal(t, addrBech32, m[0].Address, "Did not serve keys Address correctly")
|
||||
|
@ -224,10 +224,10 @@ func TestCoinSend(t *testing.T) {
|
|||
|
||||
bz, err := hex.DecodeString("8FA6AB57AD6870F6B5B2E57735F38F2F30E73CB6")
|
||||
require.NoError(t, err)
|
||||
someFakeAddr := sdk.MustBech32ifyAcc(bz)
|
||||
someFakeAddr := sdk.Address(bz)
|
||||
|
||||
// query empty
|
||||
res, body := Request(t, port, "GET", "/accounts/"+someFakeAddr, nil)
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/accounts/%s", someFakeAddr), nil)
|
||||
require.Equal(t, http.StatusNoContent, res.StatusCode, body)
|
||||
|
||||
acc := getAccount(t, port, addr)
|
||||
|
@ -334,8 +334,7 @@ func TestTxs(t *testing.T) {
|
|||
|
||||
// query sender
|
||||
// also tests url decoding
|
||||
addrBech := sdk.MustBech32ifyAcc(addr)
|
||||
res, body = Request(t, port, "GET", "/txs?tag=sender_bech32=%27"+addrBech+"%27", nil)
|
||||
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=sender_bech32=%%27%s%%27", addr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
err = cdc.UnmarshalJSON([]byte(body), &indexedTxs)
|
||||
|
@ -344,8 +343,7 @@ func TestTxs(t *testing.T) {
|
|||
require.Equal(t, resultTx.Height, indexedTxs[0].Height)
|
||||
|
||||
// query recipient
|
||||
receiveAddrBech := sdk.MustBech32ifyAcc(receiveAddr)
|
||||
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=recipient_bech32='%s'", receiveAddrBech), nil)
|
||||
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=recipient_bech32='%s'", receiveAddr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
err = cdc.UnmarshalJSON([]byte(body), &indexedTxs)
|
||||
|
@ -382,7 +380,7 @@ func TestBonding(t *testing.T) {
|
|||
cleanup, pks, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
|
||||
defer cleanup()
|
||||
|
||||
validator1Owner := pks[0].Address()
|
||||
validator1Owner := sdk.Address(pks[0].Address())
|
||||
|
||||
// create bond TX
|
||||
resultTx := doDelegate(t, port, seed, name, password, addr, validator1Owner)
|
||||
|
|
|
@ -85,7 +85,7 @@ func CreateAddr(t *testing.T, name, password string, kb crkeys.Keybase) (addr sd
|
|||
var err error
|
||||
info, seed, err = kb.CreateMnemonic(name, crkeys.English, password, crkeys.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
addr = info.GetPubKey().Address()
|
||||
addr = sdk.Address(info.GetPubKey().Address())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.Address) (
|
|||
for _, gdValidator := range genDoc.Validators {
|
||||
pk := gdValidator.PubKey
|
||||
validatorsPKs = append(validatorsPKs, pk) // append keys for output
|
||||
appGenTx, _, _, err := gapp.GaiaAppGenTxNF(cdc, pk, sdk.MustBech32ifyAcc(pk.Address()), "test_val1")
|
||||
appGenTx, _, _, err := gapp.GaiaAppGenTxNF(cdc, pk, sdk.Address(pk.Address()), "test_val1")
|
||||
require.NoError(t, err)
|
||||
appGenTxs = append(appGenTxs, appGenTx)
|
||||
}
|
||||
|
|
|
@ -103,13 +103,13 @@ func MustBech32ifyAccPub(pub crypto.PubKey) string {
|
|||
}
|
||||
|
||||
// Bech32ifyVal returns the bech32 encoded string for a validator address
|
||||
func Bech32ifyVal(addr Address) (string, error) {
|
||||
return bech32.ConvertAndEncode(Bech32PrefixValAddr, addr.Bytes())
|
||||
func Bech32ifyVal(bz []byte) (string, error) {
|
||||
return bech32.ConvertAndEncode(Bech32PrefixValAddr, bz)
|
||||
}
|
||||
|
||||
// MustBech32ifyVal panics on bech32-encoding failure
|
||||
func MustBech32ifyVal(addr Address) string {
|
||||
enc, err := Bech32ifyVal(addr)
|
||||
func MustBech32ifyVal(bz []byte) string {
|
||||
enc, err := Bech32ifyVal(bz)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
package mock
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
dbm "github.com/tendermint/tendermint/libs/db"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
bam "github.com/cosmos/cosmos-sdk/baseapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
// Extended ABCI application
|
||||
type App struct {
|
||||
*bam.BaseApp
|
||||
Cdc *wire.Codec // public since the codec is passed into the module anyways.
|
||||
KeyMain *sdk.KVStoreKey
|
||||
KeyAccount *sdk.KVStoreKey
|
||||
|
||||
// TODO: Abstract this out from not needing to be auth specifically
|
||||
AccountMapper auth.AccountMapper
|
||||
FeeCollectionKeeper auth.FeeCollectionKeeper
|
||||
|
||||
GenesisAccounts []auth.Account
|
||||
}
|
||||
|
||||
// partially construct a new app on the memstore for module and genesis testing
|
||||
func NewApp() *App {
|
||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app")
|
||||
db := dbm.NewMemDB()
|
||||
|
||||
// create the cdc with some standard codecs
|
||||
cdc := wire.NewCodec()
|
||||
sdk.RegisterWire(cdc)
|
||||
wire.RegisterCrypto(cdc)
|
||||
auth.RegisterWire(cdc)
|
||||
|
||||
// create your application object
|
||||
app := &App{
|
||||
BaseApp: bam.NewBaseApp("mock", cdc, logger, db),
|
||||
Cdc: cdc,
|
||||
KeyMain: sdk.NewKVStoreKey("main"),
|
||||
KeyAccount: sdk.NewKVStoreKey("acc"),
|
||||
}
|
||||
|
||||
// define the accountMapper
|
||||
app.AccountMapper = auth.NewAccountMapper(
|
||||
app.Cdc,
|
||||
app.KeyAccount, // target store
|
||||
&auth.BaseAccount{}, // prototype
|
||||
)
|
||||
|
||||
// initialize the app, the chainers and blockers can be overwritten before calling complete setup
|
||||
app.SetInitChainer(app.InitChainer)
|
||||
|
||||
app.SetAnteHandler(auth.NewAnteHandler(app.AccountMapper, app.FeeCollectionKeeper))
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
// complete the application setup after the routes have been registered
|
||||
func (app *App) CompleteSetup(newKeys []*sdk.KVStoreKey) error {
|
||||
newKeys = append(newKeys, app.KeyMain)
|
||||
newKeys = append(newKeys, app.KeyAccount)
|
||||
app.MountStoresIAVL(newKeys...)
|
||||
err := app.LoadLatestVersion(app.KeyMain)
|
||||
return err
|
||||
}
|
||||
|
||||
// custom logic for initialization
|
||||
func (app *App) InitChainer(ctx sdk.Context, _ abci.RequestInitChain) abci.ResponseInitChain {
|
||||
|
||||
// load the accounts
|
||||
for _, genacc := range app.GenesisAccounts {
|
||||
acc := app.AccountMapper.NewAccountWithAddress(ctx, genacc.GetAddress())
|
||||
err := acc.SetCoins(genacc.GetCoins())
|
||||
if err != nil {
|
||||
// TODO: Handle with #870
|
||||
panic(err)
|
||||
}
|
||||
app.AccountMapper.SetAccount(ctx, acc)
|
||||
}
|
||||
|
||||
return abci.ResponseInitChain{}
|
||||
}
|
||||
|
||||
// Generate genesis accounts loaded with coins, and returns their addresses, pubkeys, and privkeys
|
||||
func CreateGenAccounts(numAccs int64, genCoins sdk.Coins) (genAccs []auth.Account, addrs []sdk.Address, pubKeys []crypto.PubKey, privKeys []crypto.PrivKey) {
|
||||
for i := int64(0); i < numAccs; i++ {
|
||||
privKey := crypto.GenPrivKeyEd25519()
|
||||
pubKey := privKey.PubKey()
|
||||
addr := sdk.Address(pubKey.Address())
|
||||
|
||||
genAcc := &auth.BaseAccount{
|
||||
Address: addr,
|
||||
Coins: genCoins,
|
||||
}
|
||||
|
||||
genAccs = append(genAccs, genAcc)
|
||||
privKeys = append(privKeys, privKey)
|
||||
pubKeys = append(pubKeys, pubKey)
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
|
@ -18,12 +18,12 @@ import (
|
|||
// test bank module in a mock application
|
||||
var (
|
||||
priv1 = crypto.GenPrivKeyEd25519()
|
||||
addr1 = priv1.PubKey().Address()
|
||||
addr1 = sdk.Address(priv1.PubKey().Address())
|
||||
priv2 = crypto.GenPrivKeyEd25519()
|
||||
addr2 = priv2.PubKey().Address()
|
||||
addr3 = crypto.GenPrivKeyEd25519().PubKey().Address()
|
||||
addr2 = sdk.Address(priv2.PubKey().Address())
|
||||
addr3 = sdk.Address(crypto.GenPrivKeyEd25519().PubKey().Address())
|
||||
priv4 = crypto.GenPrivKeyEd25519()
|
||||
addr4 = priv4.PubKey().Address()
|
||||
addr4 = sdk.Address(priv4.PubKey().Address())
|
||||
coins = sdk.Coins{sdk.NewCoin("foocoin", 10)}
|
||||
halfCoins = sdk.Coins{sdk.NewCoin("foocoin", 5)}
|
||||
manyCoins = sdk.Coins{sdk.NewCoin("foocoin", 1), sdk.NewCoin("barcoin", 1)}
|
||||
|
|
|
@ -80,7 +80,7 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.CoreCont
|
|||
}
|
||||
|
||||
// build message
|
||||
msg := client.BuildMsg(info.GetPubKey().Address(), to, m.Amount)
|
||||
msg := client.BuildMsg(sdk.Address(info.GetPubKey().Address()), to, m.Amount)
|
||||
if err != nil { // XXX rechecking same error ?
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
|
|
@ -124,10 +124,10 @@ func (msg MsgIssue) GetSignBytes() []byte {
|
|||
outputs = append(outputs, output.GetSignBytes())
|
||||
}
|
||||
b, err := msgCdc.MarshalJSON(struct {
|
||||
Banker string `json:"banker"`
|
||||
Banker sdk.Address `json:"banker"`
|
||||
Outputs []json.RawMessage `json:"outputs"`
|
||||
}{
|
||||
Banker: sdk.MustBech32ifyAcc(msg.Banker),
|
||||
Banker: msg.Banker,
|
||||
Outputs: outputs,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -152,13 +152,7 @@ type Input struct {
|
|||
|
||||
// Return bytes to sign for Input
|
||||
func (in Input) GetSignBytes() []byte {
|
||||
bin, err := msgCdc.MarshalJSON(struct {
|
||||
Address string `json:"address"`
|
||||
Coins sdk.Coins `json:"coins"`
|
||||
}{
|
||||
Address: sdk.MustBech32ifyAcc(in.Address),
|
||||
Coins: in.Coins,
|
||||
})
|
||||
bin, err := msgCdc.MarshalJSON(in)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -199,13 +193,7 @@ type Output struct {
|
|||
|
||||
// Return bytes to sign for Output
|
||||
func (out Output) GetSignBytes() []byte {
|
||||
bin, err := msgCdc.MarshalJSON(struct {
|
||||
Address string `json:"address"`
|
||||
Coins sdk.Coins `json:"coins"`
|
||||
}{
|
||||
Address: sdk.MustBech32ifyAcc(out.Address),
|
||||
Coins: out.Coins,
|
||||
})
|
||||
bin, err := msgCdc.MarshalJSON(out)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -77,16 +77,15 @@ func StringToVoteOption(str string) (VoteOption, sdk.Error) {
|
|||
|
||||
// Rest Deposits
|
||||
type DepositRest struct {
|
||||
Depositer string `json:"voter"` // address of the voter
|
||||
Depositer sdk.Address `json:"depositer"` // address of the depositer
|
||||
ProposalID int64 `json:"proposal_id"` // proposalID of the proposal
|
||||
Amount sdk.Coins `json:"option"`
|
||||
}
|
||||
|
||||
// Turn any Deposit to a DepositRest
|
||||
func DepositToRest(deposit Deposit) DepositRest {
|
||||
bechAddr := sdk.MustBech32ifyAcc(deposit.Depositer)
|
||||
return DepositRest{
|
||||
Depositer: bechAddr,
|
||||
Depositer: deposit.Depositer,
|
||||
ProposalID: deposit.ProposalID,
|
||||
Amount: deposit.Amount,
|
||||
}
|
||||
|
@ -94,16 +93,15 @@ func DepositToRest(deposit Deposit) DepositRest {
|
|||
|
||||
// Rest Votes
|
||||
type VoteRest struct {
|
||||
Voter string `json:"voter"` // address of the voter
|
||||
Voter sdk.Address `json:"voter"` // address of the voter
|
||||
ProposalID int64 `json:"proposal_id"` // proposalID of the proposal
|
||||
Option string `json:"option"`
|
||||
}
|
||||
|
||||
// Turn any Vote to a VoteRest
|
||||
func VoteToRest(vote Vote) VoteRest {
|
||||
bechAddr, _ := sdk.Bech32ifyAcc(vote.Voter)
|
||||
return VoteRest{
|
||||
Voter: bechAddr,
|
||||
Voter: vote.Voter,
|
||||
ProposalID: vote.ProposalID,
|
||||
Option: VoteOptionToString(vote.Option),
|
||||
}
|
||||
|
|
|
@ -42,8 +42,7 @@ func ErrAlreadyFinishedProposal(codespace sdk.CodespaceType, proposalID int64) s
|
|||
}
|
||||
|
||||
func ErrAddressNotStaked(codespace sdk.CodespaceType, address sdk.Address) sdk.Error {
|
||||
bechAddr, _ := sdk.Bech32ifyAcc(address)
|
||||
return sdk.NewError(codespace, CodeAddressNotStaked, fmt.Sprintf("Address %s is not staked and is thus ineligible to vote", bechAddr))
|
||||
return sdk.NewError(codespace, CodeAddressNotStaked, fmt.Sprintf("Address %s is not staked and is thus ineligible to vote", address))
|
||||
}
|
||||
|
||||
func ErrInvalidTitle(codespace sdk.CodespaceType, title string) sdk.Error {
|
||||
|
|
|
@ -35,7 +35,7 @@ func TestIBCMsgs(t *testing.T) {
|
|||
destChain := "dest-chain"
|
||||
|
||||
priv1 := crypto.GenPrivKeyEd25519()
|
||||
addr1 := priv1.PubKey().Address()
|
||||
addr1 := sdk.Address(priv1.PubKey().Address())
|
||||
coins := sdk.Coins{sdk.NewCoin("foocoin", 10)}
|
||||
var emptyCoins sdk.Coins
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ func TransferRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.Core
|
|||
to := sdk.Address(bz)
|
||||
|
||||
// build message
|
||||
packet := ibc.NewIBCPacket(info.GetPubKey().Address(), to, m.Amount, m.SrcChainID, destChainID)
|
||||
packet := ibc.NewIBCPacket(sdk.Address(info.GetPubKey().Address()), to, m.Amount, m.SrcChainID, destChainID)
|
||||
msg := ibc.IBCTransferMsg{packet}
|
||||
|
||||
// add gas to context
|
||||
|
|
|
@ -43,19 +43,7 @@ func NewIBCPacket(srcAddr sdk.Address, destAddr sdk.Address, coins sdk.Coins,
|
|||
|
||||
//nolint
|
||||
func (p IBCPacket) GetSignBytes() []byte {
|
||||
b, err := msgCdc.MarshalJSON(struct {
|
||||
SrcAddr string
|
||||
DestAddr string
|
||||
Coins sdk.Coins
|
||||
SrcChain string
|
||||
DestChain string
|
||||
}{
|
||||
SrcAddr: sdk.MustBech32ifyAcc(p.SrcAddr),
|
||||
DestAddr: sdk.MustBech32ifyAcc(p.DestAddr),
|
||||
Coins: p.Coins,
|
||||
SrcChain: p.SrcChain,
|
||||
DestChain: p.DestChain,
|
||||
})
|
||||
b, err := msgCdc.MarshalJSON(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -121,11 +109,11 @@ func (msg IBCReceiveMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.R
|
|||
func (msg IBCReceiveMsg) GetSignBytes() []byte {
|
||||
b, err := msgCdc.MarshalJSON(struct {
|
||||
IBCPacket json.RawMessage
|
||||
Relayer string
|
||||
Relayer sdk.Address
|
||||
Sequence int64
|
||||
}{
|
||||
IBCPacket: json.RawMessage(msg.IBCPacket.GetSignBytes()),
|
||||
Relayer: sdk.MustBech32ifyAcc(msg.Relayer),
|
||||
Relayer: msg.Relayer,
|
||||
Sequence: msg.Sequence,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
var (
|
||||
priv1 = crypto.GenPrivKeyEd25519()
|
||||
addr1 = priv1.PubKey().Address()
|
||||
addr1 = sdk.Address(priv1.PubKey().Address())
|
||||
coins = sdk.Coins{sdk.NewCoin("foocoin", 10)}
|
||||
)
|
||||
|
||||
|
@ -100,7 +100,7 @@ func TestSlashingMsgs(t *testing.T) {
|
|||
require.Equal(t, addr1, validator.Owner)
|
||||
require.Equal(t, sdk.Bonded, validator.Status())
|
||||
require.True(sdk.RatEq(t, sdk.NewRat(10), validator.PoolShares.Bonded()))
|
||||
unrevokeMsg := MsgUnrevoke{ValidatorAddr: validator.PubKey.Address()}
|
||||
unrevokeMsg := MsgUnrevoke{ValidatorAddr: sdk.Address(validator.PubKey.Address())}
|
||||
|
||||
checkValidatorSigningInfo(t, mapp, keeper, addr1, false)
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ func GetCmdQuerySigningInfo(storeName string, cdc *wire.Codec) *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
key := slashing.GetValidatorSigningInfoKey(pk.Address())
|
||||
key := slashing.GetValidatorSigningInfoKey(sdk.Address(pk.Address()))
|
||||
ctx := context.NewCoreContextFromViper()
|
||||
res, err := ctx.QueryStore(key, storeName)
|
||||
if err != nil {
|
||||
|
|
|
@ -30,7 +30,7 @@ func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result {
|
|||
return ErrValidatorNotRevoked(k.codespace).Result()
|
||||
}
|
||||
|
||||
addr := validator.GetPubKey().Address()
|
||||
addr := sdk.Address(validator.GetPubKey().Address())
|
||||
|
||||
// Signing info must exist
|
||||
info, found := k.getValidatorSigningInfo(ctx, addr)
|
||||
|
|
|
@ -34,7 +34,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, pubkey crypto.PubKey, infracti
|
|||
logger := ctx.Logger().With("module", "x/slashing")
|
||||
time := ctx.BlockHeader().Time
|
||||
age := time - timestamp
|
||||
address := pubkey.Address()
|
||||
address := sdk.Address(pubkey.Address())
|
||||
|
||||
// Double sign too old
|
||||
if age > MaxEvidenceAge {
|
||||
|
@ -64,7 +64,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, pubkey crypto.PubKey, infracti
|
|||
func (k Keeper) handleValidatorSignature(ctx sdk.Context, pubkey crypto.PubKey, power int64, signed bool) {
|
||||
logger := ctx.Logger().With("module", "x/slashing")
|
||||
height := ctx.BlockHeight()
|
||||
address := pubkey.Address()
|
||||
address := sdk.Address(pubkey.Address())
|
||||
|
||||
// Local index, so counts blocks validator *should* have signed
|
||||
// Will use the 0-value default signing info if not present, except for start height
|
||||
|
|
|
@ -14,14 +14,23 @@ import (
|
|||
|
||||
var (
|
||||
priv1 = crypto.GenPrivKeyEd25519()
|
||||
addr1 = priv1.PubKey().Address()
|
||||
addr1 = sdk.Address(priv1.PubKey().Address())
|
||||
priv2 = crypto.GenPrivKeyEd25519()
|
||||
addr2 = priv2.PubKey().Address()
|
||||
addr3 = crypto.GenPrivKeyEd25519().PubKey().Address()
|
||||
addr2 = sdk.Address(priv2.PubKey().Address())
|
||||
addr3 = sdk.Address(crypto.GenPrivKeyEd25519().PubKey().Address())
|
||||
priv4 = crypto.GenPrivKeyEd25519()
|
||||
<<<<<<< HEAD
|
||||
addr4 = priv4.PubKey().Address()
|
||||
coins = sdk.NewCoin("foocoin", 10)
|
||||
fee = auth.StdFee{sdk.Coins{sdk.NewCoin("foocoin", 0)}, 100000}
|
||||
=======
|
||||
addr4 = sdk.Address(priv4.PubKey().Address())
|
||||
coins = sdk.Coins{{"foocoin", sdk.NewInt(10)}}
|
||||
fee = auth.StdFee{
|
||||
sdk.Coins{{"foocoin", sdk.NewInt(0)}},
|
||||
100000,
|
||||
}
|
||||
>>>>>>> asdf
|
||||
)
|
||||
|
||||
// getMockApp returns an initialized mock application for this module.
|
||||
|
|
|
@ -143,10 +143,7 @@ func TestAddr(addr string, bech string) sdk.Address {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bechexpected, err := sdk.Bech32ifyAcc(res)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bechexpected := res.String()
|
||||
if bech != bechexpected {
|
||||
panic("Bech encoding doesn't match reference")
|
||||
}
|
||||
|
@ -174,7 +171,7 @@ func createTestAddrs(numAddrs int) []sdk.Address {
|
|||
|
||||
buffer.WriteString(numString) //adding on final two digits to make addresses unique
|
||||
res, _ := sdk.GetAccAddressHex(buffer.String())
|
||||
bech, _ := sdk.Bech32ifyAcc(res)
|
||||
bech := res.String()
|
||||
addresses = append(addresses, TestAddr(buffer.String(), bech))
|
||||
buffer.Reset()
|
||||
}
|
||||
|
|
|
@ -86,19 +86,9 @@ func (d Delegation) GetBondShares() sdk.Rat { return d.Shares }
|
|||
// Delegation. An error is returned if the Delegation's delegator or validator
|
||||
// addresses cannot be Bech32 encoded.
|
||||
func (d Delegation) HumanReadableString() (string, error) {
|
||||
bechAcc, err := sdk.Bech32ifyAcc(d.DelegatorAddr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
bechVal, err := sdk.Bech32ifyAcc(d.ValidatorAddr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
resp := "Delegation \n"
|
||||
resp += fmt.Sprintf("Delegator: %s\n", bechAcc)
|
||||
resp += fmt.Sprintf("Validator: %s\n", bechVal)
|
||||
resp += fmt.Sprintf("Delegator: %s\n", d.DelegatorAddr)
|
||||
resp += fmt.Sprintf("Validator: %s\n", d.ValidatorAddr)
|
||||
resp += fmt.Sprintf("Shares: %s", d.Shares.String())
|
||||
resp += fmt.Sprintf("Height: %d", d.Height)
|
||||
|
||||
|
@ -179,6 +169,7 @@ func (d UnbondingDelegation) Equal(d2 UnbondingDelegation) bool {
|
|||
// UnbondingDelegation. An error is returned if the UnbondingDelegation's
|
||||
// delegator or validator addresses cannot be Bech32 encoded.
|
||||
func (d UnbondingDelegation) HumanReadableString() (string, error) {
|
||||
<<<<<<< HEAD
|
||||
bechAcc, err := sdk.Bech32ifyAcc(d.DelegatorAddr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -189,9 +180,11 @@ func (d UnbondingDelegation) HumanReadableString() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> asdf
|
||||
resp := "Unbonding Delegation \n"
|
||||
resp += fmt.Sprintf("Delegator: %s\n", bechAcc)
|
||||
resp += fmt.Sprintf("Validator: %s\n", bechVal)
|
||||
resp += fmt.Sprintf("Delegator: %s\n", d.DelegatorAddr)
|
||||
resp += fmt.Sprintf("Validator: %s\n", d.ValidatorAddr)
|
||||
resp += fmt.Sprintf("Creation height: %v\n", d.CreationHeight)
|
||||
resp += fmt.Sprintf("Min time to unbond (unix): %v\n", d.MinTime)
|
||||
resp += fmt.Sprintf("Expected balance: %s", d.Balance.String())
|
||||
|
@ -285,6 +278,7 @@ func (d Redelegation) Equal(d2 Redelegation) bool {
|
|||
// Redelegation. An error is returned if the UnbondingDelegation's delegator or
|
||||
// validator addresses cannot be Bech32 encoded.
|
||||
func (d Redelegation) HumanReadableString() (string, error) {
|
||||
<<<<<<< HEAD
|
||||
bechAcc, err := sdk.Bech32ifyAcc(d.DelegatorAddr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -300,10 +294,12 @@ func (d Redelegation) HumanReadableString() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> asdf
|
||||
resp := "Redelegation \n"
|
||||
resp += fmt.Sprintf("Delegator: %s\n", bechAcc)
|
||||
resp += fmt.Sprintf("Source Validator: %s\n", bechValSrc)
|
||||
resp += fmt.Sprintf("Destination Validator: %s\n", bechValDst)
|
||||
resp += fmt.Sprintf("Delegator: %s\n", d.DelegatorAddr)
|
||||
resp += fmt.Sprintf("Source Validator: %s\n", d.ValidatorSrcAddr)
|
||||
resp += fmt.Sprintf("Destination Validator: %s\n", d.ValidatorDstAddr)
|
||||
resp += fmt.Sprintf("Creation height: %v\n", d.CreationHeight)
|
||||
resp += fmt.Sprintf("Min time to unbond (unix): %v\n", d.MinTime)
|
||||
resp += fmt.Sprintf("Source shares: %s", d.SharesSrc.String())
|
||||
|
|
|
@ -155,11 +155,11 @@ func (msg MsgDelegate) GetSigners() []sdk.Address {
|
|||
// get the bytes for the message signer to sign on
|
||||
func (msg MsgDelegate) GetSignBytes() []byte {
|
||||
b, err := MsgCdc.MarshalJSON(struct {
|
||||
DelegatorAddr string `json:"delegator_addr"`
|
||||
DelegatorAddr sdk.Address `json:"delegator_addr"`
|
||||
ValidatorAddr string `json:"validator_addr"`
|
||||
Bond sdk.Coin `json:"bond"`
|
||||
}{
|
||||
DelegatorAddr: sdk.MustBech32ifyAcc(msg.DelegatorAddr),
|
||||
DelegatorAddr: msg.DelegatorAddr,
|
||||
ValidatorAddr: sdk.MustBech32ifyVal(msg.ValidatorAddr),
|
||||
Bond: msg.Bond,
|
||||
})
|
||||
|
@ -213,14 +213,14 @@ func (msg MsgBeginRedelegate) GetSigners() []sdk.Address {
|
|||
// get the bytes for the message signer to sign on
|
||||
func (msg MsgBeginRedelegate) GetSignBytes() []byte {
|
||||
b, err := MsgCdc.MarshalJSON(struct {
|
||||
DelegatorAddr string `json:"delegator_addr"`
|
||||
DelegatorAddr sdk.Address `json:"delegator_addr"`
|
||||
ValidatorSrcAddr string `json:"validator_src_addr"`
|
||||
ValidatorDstAddr string `json:"validator_dst_addr"`
|
||||
SharesAmount string `json:"shares"`
|
||||
}{
|
||||
DelegatorAddr: sdk.MustBech32ifyAcc(msg.DelegatorAddr),
|
||||
ValidatorSrcAddr: sdk.MustBech32ifyVal(msg.ValidatorSrcAddr),
|
||||
ValidatorDstAddr: sdk.MustBech32ifyVal(msg.ValidatorDstAddr),
|
||||
DelegatorAddr: msg.DelegatorAddr,
|
||||
ValidatorSrcAddr: sdk.MustBech32ifyVal(msg.ValidatorSrcAddr.Bytes()),
|
||||
ValidatorDstAddr: sdk.MustBech32ifyVal(msg.ValidatorDstAddr.Bytes()),
|
||||
SharesAmount: msg.SharesAmount.String(),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -275,11 +275,11 @@ func (msg MsgCompleteRedelegate) GetSigners() []sdk.Address {
|
|||
// get the bytes for the message signer to sign on
|
||||
func (msg MsgCompleteRedelegate) GetSignBytes() []byte {
|
||||
b, err := MsgCdc.MarshalJSON(struct {
|
||||
DelegatorAddr string `json:"delegator_addr"`
|
||||
DelegatorAddr sdk.Address `json:"delegator_addr"`
|
||||
ValidatorSrcAddr string `json:"validator_src_addr"`
|
||||
ValidatorDstAddr string `json:"validator_dst_addr"`
|
||||
}{
|
||||
DelegatorAddr: sdk.MustBech32ifyAcc(msg.DelegatorAddr),
|
||||
DelegatorAddr: msg.DelegatorAddr,
|
||||
ValidatorSrcAddr: sdk.MustBech32ifyVal(msg.ValidatorSrcAddr),
|
||||
ValidatorDstAddr: sdk.MustBech32ifyVal(msg.ValidatorDstAddr),
|
||||
})
|
||||
|
@ -327,11 +327,11 @@ func (msg MsgBeginUnbonding) GetSigners() []sdk.Address { return []sdk.Address{m
|
|||
// get the bytes for the message signer to sign on
|
||||
func (msg MsgBeginUnbonding) GetSignBytes() []byte {
|
||||
b, err := MsgCdc.MarshalJSON(struct {
|
||||
DelegatorAddr string `json:"delegator_addr"`
|
||||
DelegatorAddr sdk.Address `json:"delegator_addr"`
|
||||
ValidatorAddr string `json:"validator_addr"`
|
||||
SharesAmount string `json:"shares_amount"`
|
||||
}{
|
||||
DelegatorAddr: sdk.MustBech32ifyAcc(msg.DelegatorAddr),
|
||||
DelegatorAddr: msg.DelegatorAddr,
|
||||
ValidatorAddr: sdk.MustBech32ifyVal(msg.ValidatorAddr),
|
||||
SharesAmount: msg.SharesAmount.String(),
|
||||
})
|
||||
|
@ -378,11 +378,11 @@ func (msg MsgCompleteUnbonding) GetSigners() []sdk.Address { return []sdk.Addres
|
|||
// get the bytes for the message signer to sign on
|
||||
func (msg MsgCompleteUnbonding) GetSignBytes() []byte {
|
||||
b, err := MsgCdc.MarshalJSON(struct {
|
||||
DelegatorAddr string `json:"delegator_addr"`
|
||||
DelegatorAddr sdk.Address `json:"delegator_addr"`
|
||||
ValidatorAddr string `json:"validator_src_addr"`
|
||||
}{
|
||||
DelegatorAddr: sdk.MustBech32ifyAcc(msg.DelegatorAddr),
|
||||
ValidatorAddr: sdk.MustBech32ifyVal(msg.ValidatorAddr),
|
||||
DelegatorAddr: msg.DelegatorAddr,
|
||||
ValidatorAddr: sdk.MustBech32ifyVal(msg.ValidatorAddr.Bytes()),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -14,9 +14,9 @@ var (
|
|||
pk1 = crypto.GenPrivKeyEd25519().PubKey()
|
||||
pk2 = crypto.GenPrivKeyEd25519().PubKey()
|
||||
pk3 = crypto.GenPrivKeyEd25519().PubKey()
|
||||
addr1 = pk1.Address()
|
||||
addr2 = pk2.Address()
|
||||
addr3 = pk3.Address()
|
||||
addr1 = sdk.Address(pk1.Address())
|
||||
addr2 = sdk.Address(pk2.Address())
|
||||
addr3 = sdk.Address(pk3.Address())
|
||||
|
||||
emptyAddr sdk.Address
|
||||
emptyPubkey crypto.PubKey
|
||||
|
|
|
@ -394,18 +394,13 @@ func (v Validator) GetBondHeight() int64 { return v.BondHeight }
|
|||
// validator. An error is returned if the owner or the owner's public key
|
||||
// cannot be converted to Bech32 format.
|
||||
func (v Validator) HumanReadableString() (string, error) {
|
||||
bechOwner, err := sdk.Bech32ifyAcc(v.Owner)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
bechVal, err := sdk.Bech32ifyValPub(v.PubKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
resp := "Validator \n"
|
||||
resp += fmt.Sprintf("Owner: %s\n", bechOwner)
|
||||
resp += fmt.Sprintf("Owner: %s\n", v.Owner)
|
||||
resp += fmt.Sprintf("Validator: %s\n", bechVal)
|
||||
resp += fmt.Sprintf("Shares: Status %s, Amount: %s\n", sdk.BondStatusToString(v.PoolShares.Status), v.PoolShares.Amount.FloatString())
|
||||
resp += fmt.Sprintf("Delegator Shares: %s\n", v.DelegatorShares.FloatString())
|
||||
|
|
Loading…
Reference in New Issue