diff --git a/codec/op.go b/codec/op.go index fc7e4e9..bc4f8a4 100644 --- a/codec/op.go +++ b/codec/op.go @@ -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, ), }, diff --git a/internal/compose/alpha/spec.go b/internal/compose/alpha/spec.go index 280518b..42e0e5b 100644 --- a/internal/compose/alpha/spec.go +++ b/internal/compose/alpha/spec.go @@ -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 { diff --git a/internal/compose/alpha/task/set_baker_params.go b/internal/compose/alpha/task/set_baker_params.go new file mode 100644 index 0000000..2602ee4 --- /dev/null +++ b/internal/compose/alpha/task/set_baker_params.go @@ -0,0 +1,62 @@ +// Copyright (c) 2023 Blockwatch Data Inc. +// Author: alex@blockwatch.cc, abdul@blockwatch.cc + +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 +} diff --git a/rpc/run.go b/rpc/run.go index 3a8e69a..6decf70 100644 --- a/rpc/run.go +++ b/rpc/run.go @@ -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