Skip to content

Commit

Permalink
Merge pull request #473 from KiraCore/release/v0.3.15.1
Browse files Browse the repository at this point in the history
release/v0.3.15.1 -> master
  • Loading branch information
asmodat authored May 19, 2023
2 parents 5bced5d + 26c4863 commit e57365b
Show file tree
Hide file tree
Showing 13 changed files with 1,814 additions and 252 deletions.
111 changes: 110 additions & 1 deletion app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,127 @@ func (cd CustodyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
if settings != nil && settings.CustodyEnabled {
switch kiratypes.MsgType(msg) {
case kiratypes.MsgTypeCreateCustody:
{
msg, ok := msg.(*custodytypes.MsgCreteCustodyRecord)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreteCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeAddToCustodyWhiteList:
{
msg, ok := msg.(*custodytypes.MsgAddToCustodyWhiteList)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreteCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeAddToCustodyCustodians:
{
msg, ok := msg.(*custodytypes.MsgAddToCustodyCustodians)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreteCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeRemoveFromCustodyCustodians:
{
msg, ok := msg.(*custodytypes.MsgRemoveFromCustodyCustodians)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreteCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeDropCustodyCustodians:
{
msg, ok := msg.(*custodytypes.MsgDropCustodyCustodians)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreteCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeRemoveFromCustodyWhiteList:
{
msg, ok := msg.(*custodytypes.MsgRemoveFromCustodyWhiteList)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreteCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeDropCustodyWhiteList:
{
msg := msg.(*custodytypes.MsgCreteCustodyRecord)
msg, ok := msg.(*custodytypes.MsgDropCustodyWhiteList)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreteCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
Expand Down
2 changes: 2 additions & 0 deletions proto/kira/custody/custody.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message CustodySettings {
bool use_white_list = 4;
bool use_limits = 5;
string key = 6;
string next_controller = 7;
}

message CustodyKeyRecord {
Expand All @@ -22,6 +23,7 @@ message CustodyKeyRecord {
];

string key = 2;
string next_controller = 3;
}

message CustodyRecord {
Expand Down
35 changes: 33 additions & 2 deletions proto/kira/custody/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ message MsgCreteCustodyRecord {

string old_key = 3;
string new_key = 4;

string next_address = 5 ;
string target_address = 6 ;
}

message MsgDisableCustodyRecord {
Expand All @@ -53,6 +56,7 @@ message MsgDisableCustodyRecord {
];

string old_key = 2;
string target_address = 3 ;
}

message MsgAddToCustodyCustodians {
Expand All @@ -71,6 +75,9 @@ message MsgAddToCustodyCustodians {

string old_key = 3;
string new_key = 4;

string next_address = 5 ;
string target_address = 6 ;
}

message MsgRemoveFromCustodyCustodians {
Expand All @@ -89,6 +96,9 @@ message MsgRemoveFromCustodyCustodians {

string old_key = 3;
string new_key = 4;

string next_address = 5 ;
string target_address = 6 ;
}

message MsgDropCustodyCustodians {
Expand All @@ -102,6 +112,9 @@ message MsgDropCustodyCustodians {

string old_key = 2;
string new_key = 3;

string next_address = 4 ;
string target_address = 5 ;
}

message MsgAddToCustodyWhiteList {
Expand All @@ -120,6 +133,9 @@ message MsgAddToCustodyWhiteList {

string old_key = 3;
string new_key = 4;

string next_address = 5 ;
string target_address = 6 ;
}

message MsgRemoveFromCustodyWhiteList {
Expand All @@ -138,6 +154,9 @@ message MsgRemoveFromCustodyWhiteList {

string old_key = 3;
string new_key = 4;

string next_address = 5 ;
string target_address = 6 ;
}

message MsgDropCustodyWhiteList {
Expand All @@ -149,8 +168,11 @@ message MsgDropCustodyWhiteList {
(gogoproto.moretags) = "yaml:\"address\""
];

string old_key = 2;
string new_key = 3;
string old_key = 3;
string new_key = 4;

string next_address = 5 ;
string target_address = 6 ;
}

message MsgAddToCustodyLimits {
Expand All @@ -167,6 +189,9 @@ message MsgAddToCustodyLimits {
string limit = 4;
string old_key = 5;
string new_key = 6;

string next_address = 7;
string target_address = 8;
}

message MsgRemoveFromCustodyLimits {
Expand All @@ -181,6 +206,9 @@ message MsgRemoveFromCustodyLimits {
string denom = 2;
string old_key = 3;
string new_key = 4;

string next_address = 5 ;
string target_address = 6 ;
}

message MsgDropCustodyLimits {
Expand All @@ -194,6 +222,9 @@ message MsgDropCustodyLimits {

string old_key = 2;
string new_key = 3;

string next_address = 4 ;
string target_address = 5 ;
}

message MsgApproveCustodyTransaction {
Expand Down
20 changes: 18 additions & 2 deletions scripts/sekai-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1156,8 +1156,10 @@ function enableCustody() {
local FEE_DENOM=$7
local OKEY=$8
local NKEY=$9
local NEXT=$(showAddress ${10})
local TARGET=$(showAddress ${11})

sekaid tx custody create $MODE $PASSWORD $LIMITS $WHITELIST --from=$FROM --keyring-backend=test --chain-id=$NETWORK_NAME --fees="${FEE_AMOUNT}${FEE_DENOM}" --output=json --yes --home=$SEKAID_HOME --okey=$OKEY --nkey=$NKEY | txAwait 180
sekaid tx custody create $MODE $PASSWORD $LIMITS $WHITELIST --from=$FROM --keyring-backend=test --chain-id=$NETWORK_NAME --fees="${FEE_AMOUNT}${FEE_DENOM}" --output=json --yes --home=$SEKAID_HOME --okey=$OKEY --nkey=$NKEY --next=$NEXT --target=$TARGET | txAwait 180
}
# enableCustody
function disableCustody() {
Expand All @@ -1177,8 +1179,22 @@ function addCustodians() {
local FEE_DENOM=$4
local OKEY=$5
local NKEY=$6
local NEXT=$(showAddress $7)
local TARGET=$(showAddress $8)

sekaid tx custody custodians add "$ADDRESSES" --from=$FROM --keyring-backend=test --chain-id=$NETWORK_NAME --fees="${FEE_AMOUNT}${FEE_DENOM}" --output=json --yes --home=$SEKAID_HOME --okey=$OKEY --nkey=$NKEY | txAwait 180
sekaid tx custody custodians add "$ADDRESSES" --from=$FROM --keyring-backend=test --chain-id=$NETWORK_NAME --fees="${FEE_AMOUNT}${FEE_DENOM}" --output=json --yes --home=$SEKAID_HOME --okey=$OKEY --nkey=$NKEY --next=$NEXT --target=$TARGET | txAwait 180
}

# addCustodiansForce
function addCustodiansForce() {
local FROM=$1
local ADDRESSES=$2
local FEE_AMOUNT=$3
local FEE_DENOM=$4
local OKEY=$5
local NKEY=$6

sekaid tx custody custodians add "$ADDRESSES" --from=$FROM --keyring-backend=test --chain-id=$NETWORK_NAME --gas-prices="${FEE_AMOUNT}${FEE_DENOM}" --output=json --yes --home=$SEKAID_HOME --okey=$OKEY --nkey=$NKEY
}

# dropCustodians
Expand Down
Loading

0 comments on commit e57365b

Please sign in to comment.