From fbc650978a3b6933b69986bb62acfbe8e17b73b1 Mon Sep 17 00:00:00 2001 From: Huan-Cheng Chang Date: Sat, 1 Jun 2024 12:02:30 +0100 Subject: [PATCH 1/2] set baker params --- internal/compose/alpha/spec.go | 2 + .../compose/alpha/task/set_baker_params.go | 62 +++++++++++++++++++ rpc/run.go | 5 ++ 3 files changed, 69 insertions(+) create mode 100644 internal/compose/alpha/task/set_baker_params.go 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..2abcc03 100644 --- a/rpc/run.go +++ b/rpc/run.go @@ -43,6 +43,11 @@ var ( Fee: 1000, GasLimit: 1000, } + // for baker param update + DefaultBakerParamUpdateLimits = tezos.Limits{ + Fee: 1000, + GasLimit: 1000, + } // for simulating contract calls and other operations // used when no explicit costs are set DefaultSimulationLimits = tezos.Limits{ From 10ad4e3b5b95efb69f98596a9d7e83333b2c6fbb Mon Sep 17 00:00:00 2001 From: Huan-Cheng Chang Date: Tue, 18 Jun 2024 10:53:01 +0100 Subject: [PATCH 2/2] fix params --- codec/op.go | 2 +- rpc/run.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) 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/rpc/run.go b/rpc/run.go index 2abcc03..6decf70 100644 --- a/rpc/run.go +++ b/rpc/run.go @@ -36,17 +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: 1000, + GasLimit: 10000, + } + DefaultStakeLimits = tezos.Limits{ + Fee: 1000, + GasLimit: 10000, } // for simulating contract calls and other operations // used when no explicit costs are set