-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
package blockchain | ||
|
||
import "fmt" | ||
|
||
const ( | ||
defaultContractRegistryAddr = "0xd1a6f3d1ae33b4b19565a6b283d7a05c5a0decb0" | ||
|
||
sidechainSNMAddressKey = "sidechainSNMAddress" | ||
masterchainSNMAddressKey = "masterchainSNMAddress" | ||
blacklistAddressKey = "blacklistAddress" | ||
marketAddressKey = "marketV2Address" | ||
profileRegistryAddressKey = "profileRegistryAddress" | ||
oracleUsdAddressKey = "oracleUsdAddress" | ||
gatekeeperMasterchainAddressKey = "gatekeeperMasterchainAddress" | ||
gatekeeperSidechainAddressKey = "gatekeeperSidechainAddress" | ||
testnetFaucetAddressKey = "testnetFaucetAddress" | ||
oracleMultiSigAddressKey = "oracleMultiSigAddress" | ||
) | ||
|
||
func marketAddressKey(version uint) (string, error) { | ||
switch version { | ||
case 1: | ||
return "marketAddress", nil | ||
case 2: | ||
return "marketV2Address", nil | ||
default: | ||
return "", fmt.Errorf("invalid market version %d", version) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
migration_dwh: | ||
endpoint: | ||
|
||
|
||
# Local Node settings | ||
node: | ||
# Node's port to listen for client connection | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package migration | ||
|
||
import ( | ||
"context" | ||
"crypto/ecdsa" | ||
|
||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/sonm-io/core/blockchain" | ||
"github.com/sonm-io/core/insonmnia/dwh" | ||
"github.com/sonm-io/core/proto" | ||
"github.com/sonm-io/core/util/multierror" | ||
"github.com/sonm-io/core/util/xgrpc" | ||
) | ||
|
||
type MarketShredder struct { | ||
api blockchain.API | ||
dwh sonm.DWHClient | ||
} | ||
|
||
func NewV1MarketShredder(ctx context.Context, bcCfg *blockchain.Config, dwhCfg dwh.YAMLConfig) (*MarketShredder, error) { | ||
api, err := blockchain.NewAPI(ctx, blockchain.WithConfig(bcCfg), blockchain.WithVersion(1)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cc, err := xgrpc.NewClient(ctx, dwhCfg.Endpoint, credentials) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
dwh := sonm.NewDWHClient(cc) | ||
} | ||
|
||
func NewMarketShredder(api blockchain.API, dwh sonm.DWHClient) *MarketShredder { | ||
return &MarketShredder{ | ||
api: api, | ||
dwh: dwh, | ||
} | ||
} | ||
|
||
func (m *MarketShredder) WeDontNeedNoWaterLetTheMothefuckerBurn(ctx context.Context, pKey *ecdsa.PrivateKey) error { | ||
author := crypto.PubkeyToAddress(pKey.PublicKey) | ||
ordersRequest := &sonm.OrdersRequest{ | ||
AuthorID: sonm.NewEthAddress(author), | ||
} | ||
orders, err := m.dwh.GetOrders(ctx, ordersRequest) | ||
if err != nil { | ||
return err | ||
} | ||
market := m.api.Market() | ||
merr := multierror.NewMultiError() | ||
for _, order := range orders.GetOrders() { | ||
if err := market.CancelOrder(ctx, pKey, order.GetOrder().GetId().Unwrap()); err != nil { | ||
merr = multierror.Append(merr, err) | ||
} | ||
} | ||
|
||
dealsRequest := &sonm.DealsRequest{ | ||
AnyUserID: sonm.NewEthAddress(author), | ||
} | ||
deals, err := m.dwh.GetDeals(ctx, dealsRequest) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, deal := range deals.GetDeals() { | ||
// We only match masterID, but master cannot close deals. | ||
if deal.GetDeal().GetConsumerID().Unwrap() != author && deal.GetDeal().GetSupplierID().Unwrap() != author { | ||
continue | ||
} | ||
if err := market.CloseDeal(ctx, pKey, deal.GetDeal().GetId().Unwrap(), sonm.BlacklistType_BLACKLIST_NOBODY); err != nil { | ||
merr = multierror.Append(merr, err) | ||
} | ||
} | ||
return merr.ErrorOrNil() | ||
} |