Skip to content

Commit

Permalink
Merge pull request #5899 from mysteriumnetwork/revert-untested-changes
Browse files Browse the repository at this point in the history
Revert untested changes
  • Loading branch information
Guillembonet authored Oct 27, 2023
2 parents a941db3 + 4a62267 commit 0ca0df7
Show file tree
Hide file tree
Showing 26 changed files with 521 additions and 900 deletions.
2 changes: 1 addition & 1 deletion cmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (di *Dependencies) bootstrapTequilapi(nodeOptions node.Options, listener ne
},
tequilapi_endpoints.AddRouteForStop(utils.SoftKiller(di.Shutdown)),
tequilapi_endpoints.AddRoutesForAuthentication(di.Authenticator, di.JWTAuthenticator, di.SSOMystnodes),
tequilapi_endpoints.AddRoutesForIdentities(di.IdentityManager, di.IdentitySelector, di.IdentityRegistry, di.ConsumerBalanceTracker, di.AddressProvider, di.HermesChannelRepository, di.BCHelper, di.Transactor, di.BeneficiaryProvider, di.IdentityMover, di.BeneficiaryAddressStorage, di.HermesMigrator),
tequilapi_endpoints.AddRoutesForIdentities(di.IdentityManager, di.IdentitySelector, di.IdentityRegistry, di.ConsumerBalanceTracker, di.AddressProvider, di.HermesChannelRepository, di.BCHelper, di.Transactor, di.BeneficiaryProvider, di.IdentityMover, di.PayoutAddressStorage, di.HermesMigrator),
tequilapi_endpoints.AddRoutesForConnection(di.MultiConnectionManager, di.StateKeeper, di.ProposalRepository, di.IdentityRegistry, di.EventBus, di.AddressProvider),
tequilapi_endpoints.AddRoutesForSessions(di.SessionStorage),
tequilapi_endpoints.AddRoutesForConnectionLocation(di.IPResolver, di.LocationResolver, di.LocationResolver),
Expand Down
2 changes: 1 addition & 1 deletion cmd/bootstrap_mobile_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (di *Dependencies) bootstrapTequilapi(nodeOptions node.Options, listener ne
},
tequilapi_endpoints.AddRouteForStop(utils.SoftKiller(di.Shutdown)),
tequilapi_endpoints.AddRoutesForAuthentication(di.Authenticator, di.JWTAuthenticator, di.SSOMystnodes),
tequilapi_endpoints.AddRoutesForIdentities(di.IdentityManager, di.IdentitySelector, di.IdentityRegistry, di.ConsumerBalanceTracker, di.AddressProvider, di.HermesChannelRepository, di.BCHelper, di.Transactor, di.BeneficiaryProvider, di.IdentityMover, di.BeneficiaryAddressStorage, di.HermesMigrator),
tequilapi_endpoints.AddRoutesForIdentities(di.IdentityManager, di.IdentitySelector, di.IdentityRegistry, di.ConsumerBalanceTracker, di.AddressProvider, di.HermesChannelRepository, di.BCHelper, di.Transactor, di.BeneficiaryProvider, di.IdentityMover, di.PayoutAddressStorage, di.HermesMigrator),
tequilapi_endpoints.AddRoutesForConnection(di.MultiConnectionManager, di.StateKeeper, di.ProposalRepository, di.IdentityRegistry, di.EventBus, di.AddressProvider),
tequilapi_endpoints.AddRoutesForSessions(di.SessionStorage),
tequilapi_endpoints.AddRoutesForConnectionLocation(di.IPResolver, di.LocationResolver, di.LocationResolver),
Expand Down
2 changes: 2 additions & 0 deletions cmd/commands/cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ func newAutocompleter(tequilapi *tequilapi_client.Client, proposals []contract.P
readline.PcItem("new"),
readline.PcItem("unlock", readline.PcItemDynamic(getIdentityOptionList(tequilapi))),
readline.PcItem("register", readline.PcItemDynamic(getIdentityOptionList(tequilapi))),
readline.PcItem("get-payout-address", readline.PcItemDynamic(getIdentityOptionList(tequilapi))),
readline.PcItem("set-payout-address", readline.PcItemDynamic(getIdentityOptionList(tequilapi))),
readline.PcItem("beneficiary-status", readline.PcItemDynamic(getIdentityOptionList(tequilapi))),
readline.PcItem("beneficiary-set", readline.PcItemDynamic(getIdentityOptionList(tequilapi))),
readline.PcItem("settle", readline.PcItemDynamic(getIdentityOptionList(tequilapi))),
Expand Down
41 changes: 39 additions & 2 deletions cmd/commands/cli/command_identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/mysteriumnetwork/node/core/node"
"github.com/mysteriumnetwork/node/identity"
"github.com/mysteriumnetwork/node/money"
"github.com/mysteriumnetwork/payments/units"
"github.com/mysteriumnetwork/payments/crypto"
)

func (c *cliApp) identities(args []string) (err error) {
Expand All @@ -51,6 +51,8 @@ func (c *cliApp) identities(args []string) (err error) {
" " + usageUnlockIdentity,
" " + usageRegisterIdentity,
" " + usageSettle,
" " + usageSetPayoutAddress,
" " + usageGetPayoutAddress,
" " + usageSetBeneficiary,
" " + usageSetBeneficiaryStatus,
" " + usageGetReferralCode,
Expand Down Expand Up @@ -85,6 +87,10 @@ func (c *cliApp) identities(args []string) (err error) {
return c.registerIdentity(actionArgs)
case "settle":
return c.settle(actionArgs)
case "set-payout-address":
return c.setPayoutAddress(actionArgs)
case "get-payout-address":
return c.getPayoutAddress(actionArgs)
case "beneficiary-set":
return c.setBeneficiary(actionArgs)
case "beneficiary-status":
Expand Down Expand Up @@ -302,6 +308,37 @@ func (c *cliApp) settle(args []string) (err error) {
}
}

const usageGetPayoutAddress = "get-payout-address <identity>"

func (c *cliApp) getPayoutAddress(args []string) error {
if len(args) != 1 {
clio.Info("Usage: " + usageGetPayoutAddress)
return errWrongArgumentCount
}
addr, err := c.tequilapi.GetPayout(args[0])
if err != nil {
return fmt.Errorf("could not get payout address: %w", err)
}
clio.Info("Payout address: ", addr.Address)
return nil
}

const usageSetPayoutAddress = "set-payout-address <providerIdentity> <beneficiary>"

func (c *cliApp) setPayoutAddress(args []string) error {
if len(args) != 2 {
clio.Info("Usage: " + usageSetPayoutAddress)
return errWrongArgumentCount
}
err := c.tequilapi.SetPayout(args[0], args[1])
if err != nil {
return fmt.Errorf("could not set payout address: %w", err)
}

clio.Info("Payout address set to: ", args[0])
return nil
}

const usageSetBeneficiary = "beneficiary-set <providerIdentity> <beneficiary> [hermesID]"

func (c *cliApp) setBeneficiary(actionArgs []string) error {
Expand Down Expand Up @@ -441,7 +478,7 @@ func (c *cliApp) withdraw(args []string) error {
return errors.New("max withdrawal amount is 99 MYST")
}

amount = units.FloatEthToBigIntWei(amf)
amount = crypto.FloatToBigMyst(amf)
}

clio.Info("Waiting for withdrawal to complete")
Expand Down
11 changes: 6 additions & 5 deletions cmd/di.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/mysteriumnetwork/node/core/location"
"github.com/mysteriumnetwork/node/core/node"
nodevent "github.com/mysteriumnetwork/node/core/node/event"
"github.com/mysteriumnetwork/node/core/payout"
"github.com/mysteriumnetwork/node/core/port"
"github.com/mysteriumnetwork/node/core/quality"
"github.com/mysteriumnetwork/node/core/service"
Expand Down Expand Up @@ -206,10 +207,10 @@ type Dependencies struct {

ResidentCountry *identity.ResidentCountry

BeneficiaryAddressStorage beneficiary.BeneficiaryStorage
NodeStatusTracker *node.MonitoringStatusTracker
NodeStatsTracker *node.StatsTracker
uiVersionConfig versionmanager.NodeUIVersionConfig
PayoutAddressStorage *payout.AddressStorage
NodeStatusTracker *node.MonitoringStatusTracker
NodeStatsTracker *node.StatsTracker
uiVersionConfig versionmanager.NodeUIVersionConfig
}

// Bootstrap initiates all container dependencies
Expand Down Expand Up @@ -553,7 +554,7 @@ func (di *Dependencies) bootstrapNodeComponents(nodeOptions node.Options, tequil
return errors.Wrap(err, "could not subscribe consumer balance tracker to relevant events")
}

di.BeneficiaryAddressStorage = beneficiary.NewAddressStorage(di.Storage)
di.PayoutAddressStorage = payout.NewAddressStorage(di.Storage)
di.bootstrapBeneficiaryProvider(nodeOptions)

di.HermesPromiseHandler = pingpong.NewHermesPromiseHandler(pingpong.HermesPromiseHandlerDeps{
Expand Down
1 change: 0 additions & 1 deletion cmd/di_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ func (di *Dependencies) bootstrapHermesPromiseSettler(nodeOptions node.Options)
di.SettlementHistoryStorage,
di.EventBus,
di.ObserverAPI,
di.BeneficiaryAddressStorage,
pingpong.HermesPromiseSettlerConfig{
BalanceThreshold: nodeOptions.Payments.HermesPromiseSettlingThreshold,
MaxFeeThreshold: nodeOptions.Payments.MaxFeeSettlingThreshold,
Expand Down
24 changes: 9 additions & 15 deletions core/beneficiary/local_storage.go → core/payout/payout.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The "MysteriumNetwork/node" Authors.
* Copyright (C) 2021 The "MysteriumNetwork/node" Authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package beneficiary
package payout

import (
"time"
Expand All @@ -26,7 +26,7 @@ import (
)

const (
bucket = "beneficiary-address"
bucket = "payout-address-bucket"
)

// ErrInvalidAddress represents invalid address error
Expand All @@ -35,30 +35,24 @@ var (
ErrNotFound = errors.New("beneficiary not found")
)

type localStorage interface {
type storage interface {
Store(bucket string, data interface{}) error
GetOneByField(bucket string, fieldName string, key interface{}, to interface{}) error
}

// BeneficiaryStorage handles storing of beneficiary address
type BeneficiaryStorage interface {
Address(identity string) (string, error)
Save(identity, address string) error
}

// AddressStorage handles storing of beneficiary address
// AddressStorage handles storing of payout address
type AddressStorage struct {
storage localStorage
storage storage
}

// NewAddressStorage constructor
func NewAddressStorage(storage localStorage) *AddressStorage {
func NewAddressStorage(storage storage) *AddressStorage {
return &AddressStorage{
storage: storage,
}
}

// Save beneficiary address for identity
// Save save payout address for identity
func (as *AddressStorage) Save(identity, address string) error {
if !common.IsHexAddress(address) {
return ErrInvalidAddress
Expand All @@ -72,7 +66,7 @@ func (as *AddressStorage) Save(identity, address string) error {
return as.storage.Store(bucket, store)
}

// Address retrieve beneficiary address for identity
// Address retrieve payout address for identity
func (as *AddressStorage) Address(identity string) (string, error) {
result := &storedBeneficiary{}
err := as.storage.GetOneByField(bucket, "ID", identity, result)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The "MysteriumNetwork/node" Authors.
* Copyright (C) 2021 The "MysteriumNetwork/node" Authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -15,38 +15,39 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package beneficiary
package payout

import (
"io/ioutil"
"os"
"testing"

"github.com/mysteriumnetwork/node/core/storage/boltdb"
"github.com/stretchr/testify/assert"
)

func TestLocalBeneficiaryStorage(t *testing.T) {
func TestPayout(t *testing.T) {
// given:
dir, err := os.MkdirTemp("/tmp", "mysttest")
dir, err := ioutil.TempDir("/tmp", "mysttest")
assert.NoError(t, err)

defer os.RemoveAll(dir)
db, err := boltdb.NewStorage(dir)
localBeneficiaryStorage := NewAddressStorage(db)
payout := NewAddressStorage(db)

// when
addr, err := localBeneficiaryStorage.Address("random")
addr, err := payout.Address("random")
assert.Error(t, err)

// when
assert.NoError(t, localBeneficiaryStorage.Save("0x1111111111111111111111111111111111111111", "0x3333333333333333333333333333333333333333"))
assert.NoError(t, localBeneficiaryStorage.Save("0x2222222222222222222222222222222222222222", "0x6666666666666666666666666666666666666666"))
assert.NoError(t, payout.Save("0x1111111111111111111111111111111111111111", "0x3333333333333333333333333333333333333333"))
assert.NoError(t, payout.Save("0x2222222222222222222222222222222222222222", "0x6666666666666666666666666666666666666666"))

addr, err = localBeneficiaryStorage.Address("0x1111111111111111111111111111111111111111")
addr, err = payout.Address("0x1111111111111111111111111111111111111111")
assert.NoError(t, err)
assert.Equal(t, "0x3333333333333333333333333333333333333333", addr)

addr, err = localBeneficiaryStorage.Address("0x2222222222222222222222222222222222222222")
addr, err = payout.Address("0x2222222222222222222222222222222222222222")
assert.NoError(t, err)
assert.Equal(t, "0x6666666666666666666666666666666666666666", addr)
}
Loading

0 comments on commit 0ca0df7

Please sign in to comment.