fix address encoding
This commit is contained in:
parent
78da408563
commit
41c6d26ec9
11
go.mod
11
go.mod
@ -30,7 +30,6 @@ require (
|
|||||||
cosmossdk.io/tools/confix v0.1.0
|
cosmossdk.io/tools/confix v0.1.0
|
||||||
github.com/99designs/gqlgen v0.17.22
|
github.com/99designs/gqlgen v0.17.22
|
||||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f
|
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f
|
||||||
github.com/cometbft/cometbft/api v1.0.0-rc.1
|
|
||||||
github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22 // indirect
|
github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22 // indirect
|
||||||
github.com/cosmos/cosmos-proto v1.0.0-beta.5
|
github.com/cosmos/cosmos-proto v1.0.0-beta.5
|
||||||
github.com/cosmos/cosmos-sdk v1.0.0
|
github.com/cosmos/cosmos-sdk v1.0.0
|
||||||
@ -62,13 +61,8 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cosmossdk.io/server/v2/appmanager v0.0.0-20240802110823-cffeedff643d
|
|
||||||
cosmossdk.io/server/v2/stf v0.0.0-20240708142107-25e99c54bac1
|
|
||||||
cosmossdk.io/x/accounts v1.0.0-alpha.4
|
cosmossdk.io/x/accounts v1.0.0-alpha.4
|
||||||
cosmossdk.io/x/accounts/defaults/base v0.0.0-00010101000000-000000000000
|
cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91
|
||||||
cosmossdk.io/x/accounts/defaults/lockup v0.0.0-00010101000000-000000000000
|
|
||||||
cosmossdk.io/x/accounts/defaults/multisig v0.0.0-00010101000000-000000000000
|
|
||||||
cosmossdk.io/x/bank v1.0.0-alpha.4
|
|
||||||
cosmossdk.io/x/consensus v0.0.0-20241007000829-38662ecb209f
|
cosmossdk.io/x/consensus v0.0.0-20241007000829-38662ecb209f
|
||||||
cosmossdk.io/x/distribution v0.0.0-20241007000829-38662ecb209f
|
cosmossdk.io/x/distribution v0.0.0-20241007000829-38662ecb209f
|
||||||
cosmossdk.io/x/gov v1.0.0-alpha.4
|
cosmossdk.io/x/gov v1.0.0-alpha.4
|
||||||
@ -84,6 +78,8 @@ require (
|
|||||||
cosmossdk.io/core/testing v0.0.0 // indirect
|
cosmossdk.io/core/testing v0.0.0 // indirect
|
||||||
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 // indirect
|
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 // indirect
|
||||||
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect
|
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect
|
||||||
|
cosmossdk.io/server/v2/appmanager v0.0.0-20240802110823-cffeedff643d // indirect
|
||||||
|
cosmossdk.io/server/v2/stf v0.0.0-20240708142107-25e99c54bac1 // indirect
|
||||||
cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337 // indirect
|
cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337 // indirect
|
||||||
cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect
|
cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect
|
||||||
filippo.io/edwards25519 v1.1.0 // indirect
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
@ -108,6 +104,7 @@ require (
|
|||||||
github.com/cockroachdb/redact v1.1.5 // indirect
|
github.com/cockroachdb/redact v1.1.5 // indirect
|
||||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
|
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
|
||||||
github.com/cometbft/cometbft-db v1.0.1 // indirect
|
github.com/cometbft/cometbft-db v1.0.1 // indirect
|
||||||
|
github.com/cometbft/cometbft/api v1.0.0-rc.1 // indirect
|
||||||
github.com/cosmos/btcutil v1.0.5 // indirect
|
github.com/cosmos/btcutil v1.0.5 // indirect
|
||||||
github.com/cosmos/crypto v0.1.2 // indirect
|
github.com/cosmos/crypto v0.1.2 // indirect
|
||||||
github.com/cosmos/gogogateway v1.2.0 // indirect
|
github.com/cosmos/gogogateway v1.2.0 // indirect
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
coreaddress "cosmossdk.io/core/address"
|
"cosmossdk.io/core/address"
|
||||||
errorsmod "cosmossdk.io/errors"
|
errorsmod "cosmossdk.io/errors"
|
||||||
govtypes "cosmossdk.io/x/gov/types"
|
govtypes "cosmossdk.io/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types"
|
"github.com/cosmos/cosmos-sdk/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/address"
|
addresstypes "github.com/cosmos/cosmos-sdk/types/address"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,12 +20,12 @@ func AddressOrModuleAddress(preferred, alt string) types.AccAddress {
|
|||||||
if addr, err := addrCodec.StringToBytes(preferred); err == nil {
|
if addr, err := addrCodec.StringToBytes(preferred); err == nil {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
return address.Module(preferred)
|
return addresstypes.Module(preferred)
|
||||||
}
|
}
|
||||||
return address.Module(alt)
|
return addresstypes.Module(alt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckAuthorityAddress(ac coreaddress.Codec, expected sdk.AccAddress, msgaddr string) error {
|
func CheckAuthorityAddress(ac address.Codec, expected sdk.AccAddress, msgaddr string) error {
|
||||||
authority, err := ac.StringToBytes(msgaddr)
|
authority, err := ac.StringToBytes(msgaddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msgaddr)
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msgaddr)
|
||||||
|
@ -69,11 +69,14 @@ func GetCmdCommitBid() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auctionId := args[0]
|
auctionId := args[0]
|
||||||
|
fromAddr, err := clientCtx.AddressCodec.BytesToString(clientCtx.GetFromAddress())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
reveal := map[string]interface{}{
|
reveal := map[string]interface{}{
|
||||||
"chainId": chainId,
|
"chainId": chainId,
|
||||||
"auctionId": auctionId,
|
"auctionId": auctionId,
|
||||||
"bidderAddress": clientCtx.GetFromAddress().String(),
|
"bidderAddress": fromAddr,
|
||||||
"bidAmount": bidAmount.String(),
|
"bidAmount": bidAmount.String(),
|
||||||
"noise": mnemonic,
|
"noise": mnemonic,
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ func (k Keeper) CreateAuction(ctx context.Context, msg auctiontypes.MsgCreateAuc
|
|||||||
Address: sdk.AccAddress(signerAddress),
|
Address: sdk.AccAddress(signerAddress),
|
||||||
AccNum: account.GetAccountNumber(),
|
AccNum: account.GetAccountNumber(),
|
||||||
Sequence: account.GetSequence(),
|
Sequence: account.GetSequence(),
|
||||||
}.Generate()
|
}.Generate(k.addressCodec)
|
||||||
|
|
||||||
// Compute timestamps.
|
// Compute timestamps.
|
||||||
now := k.HeaderService.HeaderInfo(ctx).Time
|
now := k.HeaderService.HeaderInfo(ctx).Time
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
errorsmod "cosmossdk.io/errors"
|
errorsmod "cosmossdk.io/errors"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
|
|
||||||
|
"git.vdb.to/cerc-io/laconicd/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -27,6 +29,10 @@ func NewMsgCreateAuction(
|
|||||||
numProviders int32,
|
numProviders int32,
|
||||||
signer sdk.AccAddress,
|
signer sdk.AccAddress,
|
||||||
) MsgCreateAuction {
|
) MsgCreateAuction {
|
||||||
|
signerStr, err := utils.NewAddressCodec().BytesToString(signer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return MsgCreateAuction{
|
return MsgCreateAuction{
|
||||||
CommitsDuration: commitsDuration,
|
CommitsDuration: commitsDuration,
|
||||||
RevealsDuration: revealsDuration,
|
RevealsDuration: revealsDuration,
|
||||||
@ -36,33 +42,45 @@ func NewMsgCreateAuction(
|
|||||||
MaxPrice: maxPrice,
|
MaxPrice: maxPrice,
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
NumProviders: numProviders,
|
NumProviders: numProviders,
|
||||||
Signer: signer.String(),
|
Signer: signerStr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMsgCommitBid is the constructor function for MsgCommitBid.
|
// NewMsgCommitBid is the constructor function for MsgCommitBid.
|
||||||
func NewMsgCommitBid(auctionId string, commitHash string, signer sdk.AccAddress) MsgCommitBid {
|
func NewMsgCommitBid(auctionId string, commitHash string, signer sdk.AccAddress) MsgCommitBid {
|
||||||
|
signerStr, err := utils.NewAddressCodec().BytesToString(signer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return MsgCommitBid{
|
return MsgCommitBid{
|
||||||
AuctionId: auctionId,
|
AuctionId: auctionId,
|
||||||
CommitHash: commitHash,
|
CommitHash: commitHash,
|
||||||
Signer: signer.String(),
|
Signer: signerStr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMsgRevealBid is the constructor function for MsgRevealBid.
|
// NewMsgRevealBid is the constructor function for MsgRevealBid.
|
||||||
func NewMsgRevealBid(auctionId string, reveal string, signer sdk.AccAddress) MsgRevealBid {
|
func NewMsgRevealBid(auctionId string, reveal string, signer sdk.AccAddress) MsgRevealBid {
|
||||||
|
signerStr, err := utils.NewAddressCodec().BytesToString(signer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return MsgRevealBid{
|
return MsgRevealBid{
|
||||||
AuctionId: auctionId,
|
AuctionId: auctionId,
|
||||||
Reveal: reveal,
|
Reveal: reveal,
|
||||||
Signer: signer.String(),
|
Signer: signerStr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMsgReleaseFunds is the constructor function for MsgReleaseFunds.
|
// NewMsgReleaseFunds is the constructor function for MsgReleaseFunds.
|
||||||
func NewMsgReleaseFunds(auctionId string, signer sdk.AccAddress) MsgReleaseFunds {
|
func NewMsgReleaseFunds(auctionId string, signer sdk.AccAddress) MsgReleaseFunds {
|
||||||
|
signerStr, err := utils.NewAddressCodec().BytesToString(signer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return MsgReleaseFunds{
|
return MsgReleaseFunds{
|
||||||
AuctionId: auctionId,
|
AuctionId: auctionId,
|
||||||
Signer: signer.String(),
|
Signer: signerStr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"cosmossdk.io/core/address"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,9 +44,13 @@ type AuctionId struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate creates the auction id.
|
// Generate creates the auction id.
|
||||||
func (auctionId AuctionId) Generate() string {
|
func (auctionId AuctionId) Generate(ac address.Codec) string {
|
||||||
hasher := sha256.New()
|
hasher := sha256.New()
|
||||||
str := fmt.Sprintf("%s:%d:%d", auctionId.Address.String(), auctionId.AccNum, auctionId.Sequence)
|
addrStr, err := ac.BytesToString(auctionId.Address.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
str := fmt.Sprintf("%s:%d:%d", addrStr, auctionId.AccNum, auctionId.Sequence)
|
||||||
hasher.Write([]byte(str))
|
hasher.Write([]byte(str))
|
||||||
return hex.EncodeToString(hasher.Sum(nil))
|
return hex.EncodeToString(hasher.Sum(nil))
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ func NewKeeper(
|
|||||||
k := Keeper{
|
k := Keeper{
|
||||||
Environment: env,
|
Environment: env,
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
|
addressCodec: addressCodec,
|
||||||
logger: logger.With(log.ModuleKey, "x/"+bondtypes.ModuleName),
|
logger: logger.With(log.ModuleKey, "x/"+bondtypes.ModuleName),
|
||||||
authority: authority,
|
authority: authority,
|
||||||
accountKeeper: accountKeeper,
|
accountKeeper: accountKeeper,
|
||||||
@ -116,10 +117,13 @@ type BondId struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate creates the bond Id.
|
// Generate creates the bond Id.
|
||||||
func (bondId BondId) Generate() string {
|
func (bondId BondId) Generate(ac address.Codec) string {
|
||||||
hasher := sha256.New()
|
hasher := sha256.New()
|
||||||
// TODO use address.codec
|
addrStr, err := ac.BytesToString(bondId.Address.Bytes())
|
||||||
str := fmt.Sprintf("%s:%d:%d", bondId.Address.String(), bondId.AccNum, bondId.Sequence)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
str := fmt.Sprintf("%s:%d:%d", addrStr, bondId.AccNum, bondId.Sequence)
|
||||||
hasher.Write([]byte(str))
|
hasher.Write([]byte(str))
|
||||||
return hex.EncodeToString(hasher.Sum(nil))
|
return hex.EncodeToString(hasher.Sum(nil))
|
||||||
}
|
}
|
||||||
@ -210,14 +214,18 @@ func (k Keeper) CreateBond(ctx context.Context, ownerAddress sdk.AccAddress, coi
|
|||||||
Address: ownerAddress,
|
Address: ownerAddress,
|
||||||
AccNum: account.GetAccountNumber(),
|
AccNum: account.GetAccountNumber(),
|
||||||
Sequence: account.GetSequence(),
|
Sequence: account.GetSequence(),
|
||||||
}.Generate()
|
}.Generate(k.addressCodec)
|
||||||
|
|
||||||
maxBondAmount, err := k.getMaxBondAmount(ctx)
|
maxBondAmount, err := k.getMaxBondAmount(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
bond := bondtypes.Bond{Id: bondId, Owner: ownerAddress.String(), Balance: coins}
|
addrStr, err := k.addressCodec.BytesToString(ownerAddress)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
bond := bondtypes.Bond{Id: bondId, Owner: addrStr, Balance: coins}
|
||||||
if bond.Balance.IsAnyGT(maxBondAmount) {
|
if bond.Balance.IsAnyGT(maxBondAmount) {
|
||||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded")
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded")
|
||||||
}
|
}
|
||||||
@ -250,7 +258,11 @@ func (k Keeper) RefillBond(ctx context.Context, id string, ownerAddress sdk.AccA
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if bond.Owner != ownerAddress.String() {
|
addrStr, err := k.addressCodec.BytesToString(ownerAddress)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if bond.Owner != addrStr {
|
||||||
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch")
|
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +312,11 @@ func (k Keeper) WithdrawBond(ctx context.Context, id string, ownerAddress sdk.Ac
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if bond.Owner != ownerAddress.String() {
|
addrStr, err := k.addressCodec.BytesToString(ownerAddress)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if bond.Owner != addrStr {
|
||||||
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch")
|
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +354,11 @@ func (k Keeper) CancelBond(ctx context.Context, id string, ownerAddress sdk.AccA
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if bond.Owner != ownerAddress.String() {
|
addrStr, err := k.addressCodec.BytesToString(ownerAddress)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if bond.Owner != addrStr {
|
||||||
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch")
|
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,15 +4,21 @@ import (
|
|||||||
errorsmod "cosmossdk.io/errors"
|
errorsmod "cosmossdk.io/errors"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
|
|
||||||
|
"git.vdb.to/cerc-io/laconicd/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sdk.Msg = &MsgCreateBond{}
|
var _ sdk.Msg = &MsgCreateBond{}
|
||||||
|
|
||||||
// NewMsgCreateBond is the constructor function for MsgCreateBond.
|
// NewMsgCreateBond is the constructor function for MsgCreateBond.
|
||||||
func NewMsgCreateBond(coins sdk.Coins, signer sdk.AccAddress) MsgCreateBond {
|
func NewMsgCreateBond(coins sdk.Coins, signer sdk.AccAddress) MsgCreateBond {
|
||||||
|
signerStr, err := utils.NewAddressCodec().BytesToString(signer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return MsgCreateBond{
|
return MsgCreateBond{
|
||||||
Coins: coins,
|
Coins: coins,
|
||||||
Signer: signer.String(),
|
Signer: signerStr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
|
|
||||||
"git.vdb.to/cerc-io/laconicd/utils"
|
"git.vdb.to/cerc-io/laconicd/utils"
|
||||||
onboardingTypes "git.vdb.to/cerc-io/laconicd/x/onboarding"
|
"git.vdb.to/cerc-io/laconicd/x/onboarding"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Keeper struct {
|
type Keeper struct {
|
||||||
@ -32,8 +32,8 @@ type Keeper struct {
|
|||||||
|
|
||||||
// state management
|
// state management
|
||||||
Schema collections.Schema
|
Schema collections.Schema
|
||||||
Params collections.Item[onboardingTypes.Params]
|
Params collections.Item[onboarding.Params]
|
||||||
Participants collections.Map[string, onboardingTypes.Participant]
|
Participants collections.Map[string, onboarding.Participant]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKeeper creates a new Keeper instance
|
// NewKeeper creates a new Keeper instance
|
||||||
@ -49,11 +49,11 @@ func NewKeeper(
|
|||||||
k := Keeper{
|
k := Keeper{
|
||||||
Environment: env,
|
Environment: env,
|
||||||
addressCodec: addressCodec,
|
addressCodec: addressCodec,
|
||||||
logger: logger.With(log.ModuleKey, "x/"+onboardingTypes.ModuleName),
|
logger: logger.With(log.ModuleKey, "x/"+onboarding.ModuleName),
|
||||||
authority: authority,
|
authority: authority,
|
||||||
Params: collections.NewItem(sb, onboardingTypes.ParamsPrefix, "params", codec.CollValue[onboardingTypes.Params](cdc)),
|
Params: collections.NewItem(sb, onboarding.ParamsPrefix, "params", codec.CollValue[onboarding.Params](cdc)),
|
||||||
Participants: collections.NewMap(
|
Participants: collections.NewMap(
|
||||||
sb, onboardingTypes.ParticipantsPrefix, "participants", collections.StringKey, codec.CollValue[onboardingTypes.Participant](cdc),
|
sb, onboarding.ParticipantsPrefix, "participants", collections.StringKey, codec.CollValue[onboarding.Participant](cdc),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,9 +69,9 @@ func NewKeeper(
|
|||||||
|
|
||||||
func (k Keeper) OnboardParticipant(
|
func (k Keeper) OnboardParticipant(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
msg *onboardingTypes.MsgOnboardParticipant,
|
msg *onboarding.MsgOnboardParticipant,
|
||||||
signerAddress sdk.AccAddress,
|
signerAddress sdk.AccAddress,
|
||||||
) (*onboardingTypes.MsgOnboardParticipantResponse, error) {
|
) (*onboarding.MsgOnboardParticipantResponse, error) {
|
||||||
params, err := k.Params.Get(ctx)
|
params, err := k.Params.Get(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -96,8 +96,13 @@ func (k Keeper) OnboardParticipant(
|
|||||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Recovered ethereum address does not match the address set in payload")
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Recovered ethereum address does not match the address set in payload")
|
||||||
}
|
}
|
||||||
|
|
||||||
participant := &onboardingTypes.Participant{
|
// TODO: redundant
|
||||||
CosmosAddress: signerAddress.String(),
|
cosmosAddr, err := k.addressCodec.BytesToString(signerAddress)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
participant := &onboarding.Participant{
|
||||||
|
CosmosAddress: cosmosAddr,
|
||||||
NitroAddress: nitroAddress,
|
NitroAddress: nitroAddress,
|
||||||
Role: msg.Role,
|
Role: msg.Role,
|
||||||
KycId: msg.KycId,
|
KycId: msg.KycId,
|
||||||
@ -107,17 +112,17 @@ func (k Keeper) OnboardParticipant(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &onboardingTypes.MsgOnboardParticipantResponse{}, nil
|
return &onboarding.MsgOnboardParticipantResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) StoreParticipant(ctx context.Context, participant *onboardingTypes.Participant) error {
|
func (k Keeper) StoreParticipant(ctx context.Context, participant *onboarding.Participant) error {
|
||||||
key := participant.CosmosAddress
|
key := participant.CosmosAddress
|
||||||
return k.Participants.Set(ctx, key, *participant)
|
return k.Participants.Set(ctx, key, *participant)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListParticipants - get all participants.
|
// ListParticipants - get all participants.
|
||||||
func (k Keeper) ListParticipants(ctx context.Context) ([]*onboardingTypes.Participant, error) {
|
func (k Keeper) ListParticipants(ctx context.Context) ([]*onboarding.Participant, error) {
|
||||||
var participants []*onboardingTypes.Participant
|
var participants []*onboarding.Participant
|
||||||
|
|
||||||
iter, err := k.Participants.Iterate(ctx, nil)
|
iter, err := k.Participants.Iterate(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -137,23 +142,23 @@ func (k Keeper) ListParticipants(ctx context.Context) ([]*onboardingTypes.Partic
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetParticipantByAddress - get participant by cosmos (laconic) address.
|
// GetParticipantByAddress - get participant by cosmos (laconic) address.
|
||||||
func (k Keeper) GetParticipantByAddress(ctx context.Context, address string) (onboardingTypes.Participant, error) {
|
func (k Keeper) GetParticipantByAddress(ctx context.Context, address string) (onboarding.Participant, error) {
|
||||||
participant, err := k.Participants.Get(ctx, address)
|
participant, err := k.Participants.Get(ctx, address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, collections.ErrNotFound) {
|
if errors.Is(err, collections.ErrNotFound) {
|
||||||
return onboardingTypes.Participant{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "participant with given address not found.")
|
return onboarding.Participant{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "participant with given address not found.")
|
||||||
}
|
}
|
||||||
return onboardingTypes.Participant{}, err
|
return onboarding.Participant{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return participant, nil
|
return participant, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetParticipantByNitroAddress - get participant by nitro address.
|
// GetParticipantByNitroAddress - get participant by nitro address.
|
||||||
func (k Keeper) GetParticipantByNitroAddress(ctx context.Context, nitroAddress string) (onboardingTypes.Participant, error) {
|
func (k Keeper) GetParticipantByNitroAddress(ctx context.Context, nitroAddress string) (onboarding.Participant, error) {
|
||||||
var participant onboardingTypes.Participant
|
var participant onboarding.Participant
|
||||||
|
|
||||||
err := k.Participants.Walk(ctx, nil, func(key string, value onboardingTypes.Participant) (bool, error) {
|
err := k.Participants.Walk(ctx, nil, func(key string, value onboarding.Participant) (bool, error) {
|
||||||
if value.NitroAddress == nitroAddress {
|
if value.NitroAddress == nitroAddress {
|
||||||
participant = value
|
participant = value
|
||||||
return true, nil
|
return true, nil
|
||||||
@ -162,7 +167,7 @@ func (k Keeper) GetParticipantByNitroAddress(ctx context.Context, nitroAddress s
|
|||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return onboardingTypes.Participant{}, err
|
return onboarding.Participant{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return participant, nil
|
return participant, nil
|
||||||
|
@ -22,11 +22,11 @@ func (msg MsgOnboardParticipant) ValidateBasic() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.EthSignature) != 132 {
|
if len(msg.EthSignature) != 132 {
|
||||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid signature.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid Eth signature")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.KycId) == 0 {
|
if len(msg.KycId) == 0 {
|
||||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Empty KYC ID.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Empty KYC ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
isRoleValid := false
|
isRoleValid := false
|
||||||
|
@ -135,6 +135,7 @@ func NewKeeper(
|
|||||||
k := Keeper{
|
k := Keeper{
|
||||||
Environment: env,
|
Environment: env,
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
|
addressCodec: addressCodec,
|
||||||
logger: logger.With(log.ModuleKey, "x/"+registrytypes.ModuleName),
|
logger: logger.With(log.ModuleKey, "x/"+registrytypes.ModuleName),
|
||||||
authority: authority,
|
authority: authority,
|
||||||
accountKeeper: accountKeeper,
|
accountKeeper: accountKeeper,
|
||||||
|
@ -475,7 +475,11 @@ func (k Keeper) checkLRNAccess(ctx context.Context, signer sdk.AccAddress, lrn s
|
|||||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid LRN.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid LRN.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if authority.OwnerAddress != signer.String() {
|
signerAddr, err := k.addressCodec.BytesToString(signer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if authority.OwnerAddress != signerAddr {
|
||||||
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Access denied.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Access denied.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,16 +4,21 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
errorsmod "cosmossdk.io/errors"
|
errorsmod "cosmossdk.io/errors"
|
||||||
|
"git.vdb.to/cerc-io/laconicd/utils"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewMsgSetRecord is the constructor function for MsgSetRecord.
|
// NewMsgSetRecord is the constructor function for MsgSetRecord.
|
||||||
func NewMsgSetRecord(payload Payload, bondId string, signer sdk.AccAddress) *MsgSetRecord {
|
func NewMsgSetRecord(payload Payload, bondId string, signer sdk.AccAddress) *MsgSetRecord {
|
||||||
|
signerStr, err := utils.NewAddressCodec().BytesToString(signer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return &MsgSetRecord{
|
return &MsgSetRecord{
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
BondId: bondId,
|
BondId: bondId,
|
||||||
Signer: signer.String(),
|
Signer: signerStr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,10 +55,19 @@ func (msg MsgRenewRecord) ValidateBasic() error {
|
|||||||
|
|
||||||
// NewMsgReserveAuthority is the constructor function for MsgReserveName.
|
// NewMsgReserveAuthority is the constructor function for MsgReserveName.
|
||||||
func NewMsgReserveAuthority(name string, signer sdk.AccAddress, owner sdk.AccAddress) MsgReserveAuthority {
|
func NewMsgReserveAuthority(name string, signer sdk.AccAddress, owner sdk.AccAddress) MsgReserveAuthority {
|
||||||
|
addrCodec := utils.NewAddressCodec()
|
||||||
|
ownerStr, err := addrCodec.BytesToString(owner)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
signerStr, err := addrCodec.BytesToString(signer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return MsgReserveAuthority{
|
return MsgReserveAuthority{
|
||||||
Name: name,
|
Name: name,
|
||||||
Owner: owner.String(),
|
Owner: ownerStr,
|
||||||
Signer: signer.String(),
|
Signer: signerStr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,9 +86,13 @@ func (msg MsgReserveAuthority) ValidateBasic() error {
|
|||||||
|
|
||||||
// NewMsgSetAuthorityBond is the constructor function for MsgSetAuthorityBond.
|
// NewMsgSetAuthorityBond is the constructor function for MsgSetAuthorityBond.
|
||||||
func NewMsgSetAuthorityBond(name string, bondID string, signer sdk.AccAddress) MsgSetAuthorityBond {
|
func NewMsgSetAuthorityBond(name string, bondID string, signer sdk.AccAddress) MsgSetAuthorityBond {
|
||||||
|
signerStr, err := utils.NewAddressCodec().BytesToString(signer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return MsgSetAuthorityBond{
|
return MsgSetAuthorityBond{
|
||||||
Name: name,
|
Name: name,
|
||||||
Signer: signer.String(),
|
Signer: signerStr,
|
||||||
BondId: bondID,
|
BondId: bondID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,10 +115,14 @@ func (msg MsgSetAuthorityBond) ValidateBasic() error {
|
|||||||
|
|
||||||
// NewMsgSetName is the constructor function for MsgSetName.
|
// NewMsgSetName is the constructor function for MsgSetName.
|
||||||
func NewMsgSetName(lrn string, cid string, signer sdk.AccAddress) *MsgSetName {
|
func NewMsgSetName(lrn string, cid string, signer sdk.AccAddress) *MsgSetName {
|
||||||
|
signerStr, err := utils.NewAddressCodec().BytesToString(signer)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return &MsgSetName{
|
return &MsgSetName{
|
||||||
Lrn: lrn,
|
Lrn: lrn,
|
||||||
Cid: cid,
|
Cid: cid,
|
||||||
Signer: signer.String(),
|
Signer: signerStr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user