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(pallet): allow farmer to set extra fee on its nodes #726

Merged
merged 27 commits into from
Jun 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
95f8880
feat: dedicated node extra fee
renauter Jun 7, 2023
bb6d2f0
chore: merge development
DylanVerstraete Jun 7, 2023
75bbda4
fix: ci
DylanVerstraete Jun 7, 2023
99359cc
feat: rework check before creating node contract
DylanVerstraete Jun 7, 2023
03e3e94
chore: rework syntax
DylanVerstraete Jun 7, 2023
9ca99fa
chore: revert farmer_share concept
renauter Jun 7, 2023
8e6295d
feat: dedicated node extra fee billing
renauter Jun 7, 2023
f37d57a
test: set dedicated node extra fee
renauter Jun 7, 2023
5d2483b
feat: add migration for locks
DylanVerstraete Jun 8, 2023
29d230a
chore: merge development
DylanVerstraete Jun 8, 2023
4abcd0b
chore: complete adr
DylanVerstraete Jun 8, 2023
5d4fe9a
fix: some general fixes and refactor
DylanVerstraete Jun 8, 2023
92c74d7
fix: rework test
DylanVerstraete Jun 9, 2023
0f00251
fix: go client bill event
DylanVerstraete Jun 9, 2023
c02830a
feat: add js client methods
DylanVerstraete Jun 9, 2023
4cadce0
feat: add go client methods
DylanVerstraete Jun 9, 2023
06950b2
fix: js client
DylanVerstraete Jun 9, 2023
7a14d2f
fix: go integration tests
DylanVerstraete Jun 9, 2023
8924cf1
chore: revert contract bill event type
DylanVerstraete Jun 12, 2023
ab050c0
chore: remove println
DylanVerstraete Jun 12, 2023
3bfe18c
chore: merge development
DylanVerstraete Jun 12, 2023
ebe5870
reviews and test rework
renauter Jun 12, 2023
1d8b942
chore: rework migration v11
renauter Jun 12, 2023
1ceaad4
feat: round costs before converting back to integer
renauter Jun 12, 2023
f41931f
chore: remove todo comment
renauter Jun 13, 2023
930f5cc
Merge remote-tracking branch 'origin' into development_feat_node_extr…
renauter Jun 13, 2023
e1cb885
chore: merge development
DylanVerstraete Jun 13, 2023
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
feat: add go client methods
DylanVerstraete committed Jun 9, 2023

Verified

This commit was signed with the committer’s verified signature.
kenjis kenjis
commit 4cadce042688b45352ea519579591ca705d9e428
57 changes: 56 additions & 1 deletion clients/tfchain-client-go/node.go
Original file line number Diff line number Diff line change
@@ -667,7 +667,7 @@ func (s *Substrate) SetNodeCertificate(sudo Identity, id uint32, cert NodeCertif
return nil
}

// UpdateNodeUptime updates the node uptime to given value
// SetNodePowerState updates the node uptime to given value
func (s *Substrate) SetNodePowerState(identity Identity, up bool) (hash types.Hash, err error) {
cl, meta, err := s.GetClient()
if err != nil {
@@ -693,6 +693,7 @@ func (s *Substrate) SetNodePowerState(identity Identity, up bool) (hash types.Ha
return callResponse.Hash, nil
}

// GetPowerTarget returns the power target for a node
func (s *Substrate) GetPowerTarget(nodeID uint32) (power NodePower, err error) {
cl, meta, err := s.GetClient()
if err != nil {
@@ -728,3 +729,57 @@ func (s *Substrate) GetPowerTarget(nodeID uint32) (power NodePower, err error) {

return power, nil
}

// SetDedicatedNodePrice sets an extra price on a node expressed in mUSD
// This price will be distributed back to the farmer if the node is rented
// Setting this price also makes the node only available to rent as dedicated
func (s *Substrate) SetDedicatedNodePrice(identity Identity, nodeId uint32, price uint64) (hash types.Hash, err error) {
cl, meta, err := s.GetClient()
if err != nil {
return hash, err
}

c, err := types.NewCall(meta, "SmartContractModule.set_dedicated_node_extra_fee", nodeId, price)

if err != nil {
return hash, errors.Wrap(err, "failed to create call")
}

callResponse, err := s.Call(cl, meta, identity, c)
if err != nil {
return hash, errors.Wrap(err, "failed to update node extra price")
}

return callResponse.Hash, nil
}

// GetDedicatedeNodePrice returns the price of a dedicated node
func (s *Substrate) GetDedicatedNodePrice(nodeID uint32) (uint64, error) {
cl, meta, err := s.GetClient()
if err != nil {
return 0, err
}

bytes, err := Encode(nodeID)
if err != nil {
return 0, errors.Wrap(err, "substrate: encoding error building query arguments")
}

key, err := types.CreateStorageKey(meta, "SmartContractModule", "DedicatedNodesExtraFee", bytes)
if err != nil {
return 0, errors.Wrap(err, "failed to create substrate query key")
}

var price types.U64

ok, err := cl.RPC.State.GetStorageLatest(key, &price)
if err != nil {
return 0, err
}

if !ok {
return 0, nil
}

return uint64(price), nil
}
23 changes: 23 additions & 0 deletions clients/tfchain-client-go/node_test.go
Original file line number Diff line number Diff line change
@@ -42,3 +42,26 @@ func TestGetNodes(t *testing.T) {
require.NoError(t, err)
require.Greater(t, len(nodes), 0)
}

func TestSetDedicatedNodePrice(t *testing.T) {
var nodeID uint32

cl := startLocalConnection(t)
defer cl.Close()

identity, err := NewIdentityFromSr25519Phrase(BobMnemonics)
require.NoError(t, err)

farmID, twinID := assertCreateFarm(t, cl)

nodeID = assertCreateNode(t, cl, farmID, twinID, identity)

price := 100000000
_, err = cl.SetDedicatedNodePrice(identity, nodeID, uint64(price))
require.NoError(t, err)

priceSet, err := cl.GetDedicatedNodePrice(nodeID)
require.NoError(t, err)

require.Equal(t, uint64(price), priceSet)
}