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

feat(rpc): Transaction proxy for staking tx types #984

Merged
merged 6 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
extending Accessor interface with new staking tx types
  • Loading branch information
distractedm1nd committed Aug 4, 2022
commit e08f890c6ed30f6e68c65585dd7c2d46f4a4242f
16 changes: 8 additions & 8 deletions service/state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ func (ca *CoreAccessor) Transfer(

func (ca *CoreAccessor) CancelUnbondingDelegation(
ctx context.Context,
validator Address,
valAddr Address,
amount Int,
gasLim uint64,
) (*TxResponse, error) {
valAddr, ok := validator.(sdktypes.ValAddress)
validator, ok := valAddr.(sdktypes.ValAddress)
if !ok {
return nil, fmt.Errorf("state: unsupported address type")
}
Expand All @@ -244,7 +244,7 @@ func (ca *CoreAccessor) CancelUnbondingDelegation(
if err != nil {
return nil, err
}
msg := stakingtypes.NewMsgCancelUnbondingDelegation(from, valAddr, head.Height, coins)
msg := stakingtypes.NewMsgCancelUnbondingDelegation(from, validator, head.Height, coins)
signedTx, err := ca.constructSignedTx(ctx, msg, apptypes.SetGasLimit(gasLim))
if err != nil {
return nil, err
Expand All @@ -254,16 +254,16 @@ func (ca *CoreAccessor) CancelUnbondingDelegation(

func (ca *CoreAccessor) BeginRedelegate(
ctx context.Context,
delAddr Address,
newValidatorAddr Address,
srcValAddr,
dstValAddr Address,
amount Int,
gasLim uint64,
) (*TxResponse, error) {
srcValAddr, ok := delAddr.(sdktypes.ValAddress)
srcValidator, ok := srcValAddr.(sdktypes.ValAddress)
if !ok {
return nil, fmt.Errorf("state: unsupported address type")
}
dstValAddr, ok := newValidatorAddr.(sdktypes.ValAddress)
dstValidator, ok := dstValAddr.(sdktypes.ValAddress)
if !ok {
return nil, fmt.Errorf("state: unsupported address type")
}
Expand All @@ -272,7 +272,7 @@ func (ca *CoreAccessor) BeginRedelegate(
return nil, err
}
coins := sdktypes.NewCoin(app.BondDenom, amount)
msg := stakingtypes.NewMsgBeginRedelegate(from, srcValAddr, dstValAddr, coins)
msg := stakingtypes.NewMsgBeginRedelegate(from, srcValidator, dstValidator, coins)
signedTx, err := ca.constructSignedTx(ctx, msg, apptypes.SetGasLimit(gasLim))
if err != nil {
return nil, err
Expand Down
9 changes: 9 additions & 0 deletions service/state/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@ type Accessor interface {
SubmitTx(ctx context.Context, tx Tx) (*TxResponse, error)
// SubmitPayForData builds, signs and submits a PayForData transaction.
SubmitPayForData(ctx context.Context, nID namespace.ID, data []byte, gasLim uint64) (*TxResponse, error)

// CancelUnbondingDelegation cancels a user's pending undelegation from a validator
renaynay marked this conversation as resolved.
Show resolved Hide resolved
CancelUnbondingDelegation(ctx context.Context, valAddr Address, amount Int, gasLim uint64) (*TxResponse, error)
// BeginRedelegate sends a user's delegated tokens to a new validator for redelegation.
BeginRedelegate(ctx context.Context, srcValAddr, dstValAddr Address, amount Int, gasLim uint64) (*TxResponse, error)
// Undelegate undelegates a user's delegated tokens, unbonding them from the current validator
renaynay marked this conversation as resolved.
Show resolved Hide resolved
Undelegate(ctx context.Context, delAddr Address, amount Int, gasLim uint64) (*TxResponse, error)
// Delegate sends a user's liquid tokens to a validator for delegation
renaynay marked this conversation as resolved.
Show resolved Hide resolved
Delegate(ctx context.Context, delAddr Address, amount Int, gasLim uint64) (*TxResponse, error)
}
27 changes: 27 additions & 0 deletions service/state/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,33 @@ func (s *Service) Transfer(ctx context.Context, to Address, amount Int, gasLimit
return s.accessor.Transfer(ctx, to, amount, gasLimit)
}

func (s *Service) CancelUnbondingDelegation(
ctx context.Context,
valAddr Address,
amount Int,
gasLim uint64,
) (*TxResponse, error) {
return s.accessor.CancelUnbondingDelegation(ctx, valAddr, amount, gasLim)
}

func (s *Service) BeginRedelegate(
ctx context.Context,
srcValAddr,
dstValAddr Address,
amount Int,
gasLim uint64,
) (*TxResponse, error) {
return s.accessor.BeginRedelegate(ctx, srcValAddr, dstValAddr, amount, gasLim)
}

func (s *Service) Undelegate(ctx context.Context, delAddr Address, amount Int, gasLim uint64) (*TxResponse, error) {
return s.accessor.Undelegate(ctx, delAddr, amount, gasLim)
}

func (s *Service) Delegate(ctx context.Context, delAddr Address, amount Int, gasLim uint64) (*TxResponse, error) {
return s.accessor.Delegate(ctx, delAddr, amount, gasLim)
}

func (s *Service) Start(context.Context) error {
s.ctx, s.cancel = context.WithCancel(context.Background())
return nil
Expand Down