Add a command to set authority bond id
This commit is contained in:
parent
0b8904d7de
commit
5527c91c19
@ -115,7 +115,7 @@ func (ms msgServer) SetAuthorityBond(c context.Context, msg *registrytypes.MsgSe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = ms.k.ProcessSetAuthorityBond(ctx, *msg)
|
err = ms.k.SetAuthorityBond(ctx, *msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func (k Keeper) SaveNameAuthority(ctx sdk.Context, name string, authority *regis
|
|||||||
// updateBlockChangeSetForNameAuthority(ctx, codec, store, name)
|
// updateBlockChangeSetForNameAuthority(ctx, codec, store, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessReserveAuthority reserves a name authority.
|
// ReserveAuthority reserves a name authority.
|
||||||
func (k Keeper) ReserveAuthority(ctx sdk.Context, msg registrytypes.MsgReserveAuthority) error {
|
func (k Keeper) ReserveAuthority(ctx sdk.Context, msg registrytypes.MsgReserveAuthority) error {
|
||||||
crn := fmt.Sprintf("crn://%s", msg.GetName())
|
crn := fmt.Sprintf("crn://%s", msg.GetName())
|
||||||
parsedCrn, err := url.Parse(crn)
|
parsedCrn, err := url.Parse(crn)
|
||||||
@ -180,8 +180,63 @@ func (k Keeper) createAuthority(ctx sdk.Context, name string, owner string, isRo
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) ProcessSetAuthorityBond(ctx sdk.Context, msg registrytypes.MsgSetAuthorityBond) error {
|
func (k Keeper) SetAuthorityBond(ctx sdk.Context, msg registrytypes.MsgSetAuthorityBond) error {
|
||||||
panic("unimplemented")
|
name := msg.GetName()
|
||||||
|
signer := msg.GetSigner()
|
||||||
|
|
||||||
|
if has, err := k.HasNameAuthority(ctx, name); !has {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Name authority not found.")
|
||||||
|
}
|
||||||
|
|
||||||
|
authority, err := k.GetNameAuthority(ctx, name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if authority.OwnerAddress != signer {
|
||||||
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Access denied.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if has, err := k.bondKeeper.HasBond(ctx, msg.BondId); !has {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
|
||||||
|
}
|
||||||
|
|
||||||
|
bond, err := k.bondKeeper.GetBondById(ctx, msg.BondId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if bond.Owner != signer {
|
||||||
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// No-op if bond hasn't changed.
|
||||||
|
if authority.BondId == msg.BondId {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// Remove old bond ID mapping, if any.
|
||||||
|
// if authority.BondId != "" {
|
||||||
|
// k.RemoveBondToAuthorityIndexEntry(ctx, authority.BondId, name)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Update bond id and save name authority in store.
|
||||||
|
authority.BondId = bond.Id
|
||||||
|
if err = k.SaveNameAuthority(ctx, name, &authority); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// Add new bond ID mapping.
|
||||||
|
// k.AddBondToAuthorityIndexEntry(ctx, authority.BondId, name)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessDeleteName removes a CRN -> Record ID mapping.
|
// ProcessDeleteName removes a CRN -> Record ID mapping.
|
||||||
|
@ -71,6 +71,15 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
|||||||
{ProtoField: "owner"},
|
{ProtoField: "owner"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
RpcMethod: "SetAuthorityBond",
|
||||||
|
Use: "authority-bond [name] [bond-id]",
|
||||||
|
Short: "Associate authority with bond",
|
||||||
|
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||||
|
{ProtoField: "name"},
|
||||||
|
{ProtoField: "bond_id"},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
EnhanceCustomCommand: true, // Allow additional manual commands
|
EnhanceCustomCommand: true, // Allow additional manual commands
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user