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

tzcompose: Support operation set_delegate_parameters #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion codec/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ func (o *Op) WithSetBakerParams(edge, limit int64) *Op {
micheline.Parameters{
Entrypoint: micheline.SET_DELEGATE_PARAMETERS,
Value: micheline.NewCombPair(
micheline.NewInt64(edge),
micheline.NewInt64(limit),
micheline.NewInt64(edge),
micheline.Unit,
),
},
Expand Down
2 changes: 2 additions & 0 deletions internal/compose/alpha/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ type Task struct {
Value string `yaml:"value,omitempty"` // wait only
Log string `yaml:"log,omitempty"` // log level override
OnError ErrorMode `yaml:"on_error,omitempty"` // how to handle errors: fail|warn|ignore
Edge uint64 `yaml:"edge,omitempty"` // set_baker_params only
Limit uint64 `yaml:"limit,omitempty"` // set_baker_params only
}

func (t Task) Validate(ctx compose.Context) error {
Expand Down
62 changes: 62 additions & 0 deletions internal/compose/alpha/task/set_baker_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2023 Blockwatch Data Inc.
// Author: [email protected], [email protected]

package task

import (
"github.com/trilitech/tzgo/codec"
"github.com/trilitech/tzgo/internal/compose"
"github.com/trilitech/tzgo/internal/compose/alpha"
"github.com/trilitech/tzgo/rpc"
"github.com/trilitech/tzgo/signer"
"github.com/trilitech/tzgo/tezos"

"github.com/pkg/errors"
)

var _ alpha.TaskBuilder = (*SetBakerParamsTask)(nil)

func init() {
alpha.RegisterTask("set_baker_params", NewSetBakerParamsTask)
}

type SetBakerParamsTask struct {
BaseTask
Limit int64 // the parameter `limit_of_staking_over_baking_millionth`
Edge int64 // the parameter `edge_of_baking_over_staking_billionth`
}

func NewSetBakerParamsTask() alpha.TaskBuilder {
return &SetBakerParamsTask{}
}

func (t *SetBakerParamsTask) Type() string {
return "set_baker_params"
}

func (t *SetBakerParamsTask) Build(ctx compose.Context, task alpha.Task) (*codec.Op, *rpc.CallOptions, error) {
if err := t.parse(ctx, task); err != nil {
return nil, nil, errors.Wrap(err, "parse")
}
opts := rpc.NewCallOptions()
opts.Signer = signer.NewFromKey(t.Key)
opts.IgnoreLimits = true
op := codec.NewOp().
WithSource(t.Source).
WithSetBakerParams(t.Edge, t.Limit).
WithLimits([]tezos.Limits{rpc.DefaultBakerParamUpdateLimits}, 0)
return op, opts, nil
}

func (t *SetBakerParamsTask) Validate(ctx compose.Context, task alpha.Task) error {
return t.parse(ctx, task)
}

func (t *SetBakerParamsTask) parse(ctx compose.Context, task alpha.Task) error {
if err := t.BaseTask.parse(ctx, task); err != nil {
return err
}
t.Edge = int64(task.Edge)
t.Limit = int64(task.Limit)
return nil
}
13 changes: 11 additions & 2 deletions rpc/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ var (
// for delegation
DefaultDelegationLimitsEOA = tezos.Limits{
Fee: 1000,
GasLimit: 1000,
GasLimit: 10000,
}
// for baker registration
DefaultBakerRegistrationLimits = tezos.Limits{
Fee: 1000,
GasLimit: 1000,
GasLimit: 10000,
}
// for baker param update
DefaultBakerParamUpdateLimits = tezos.Limits{
Fee: 1000,
GasLimit: 10000,
}
DefaultStakeLimits = tezos.Limits{
Fee: 1000,
GasLimit: 10000,
}
// for simulating contract calls and other operations
// used when no explicit costs are set
Expand Down