diff --git a/Makefile b/Makefile index 112e15e..193638a 100644 --- a/Makefile +++ b/Makefile @@ -96,7 +96,7 @@ $(BIN_DIR): .PHONY: $(INSOLARD) $(INSOLARD): - $(GOBUILD) -o $(BIN_DIR)/$(INSOLARD) ${BUILD_TAGS} -ldflags "${LDFLAGS}" cmd/insolard/*.go + $(GOBUILD) -o $(BIN_DIR)/$(INSOLARD) ${BUILD_TAGS} -ldflags "${LDFLAGS}" application/cmd/insolard/*.go .PHONY: $(INSOLAR) $(INSOLAR): diff --git a/application/appfoundation/helpers.go b/application/appfoundation/helpers.go index deb93f3..3006607 100644 --- a/application/appfoundation/helpers.go +++ b/application/appfoundation/helpers.go @@ -9,44 +9,34 @@ import ( "regexp" "github.com/insolar/insolar/insolar" - "github.com/insolar/mainnet/application/genesisrefs" + "github.com/insolar/mainnet/application/genesis" ) const AllowedVersionSmartContract = 2 // Get reference CostCenter contract. func GetCostCenter() insolar.Reference { - return genesisrefs.ContractCostCenter + return genesis.ContractCostCenter } // Get reference MigrationAdminMember contract. func GetMigrationAdminMember() insolar.Reference { - return genesisrefs.ContractMigrationAdminMember -} - -// Get reference RootMember contract. -func GetRootMember() insolar.Reference { - return genesisrefs.ContractRootMember + return genesis.ContractMigrationAdminMember } // Get reference on MigrationAdmin contract. func GetMigrationAdmin() insolar.Reference { - return genesisrefs.ContractMigrationAdmin -} - -// Get reference on RootDomain contract. -func GetRootDomain() insolar.Reference { - return genesisrefs.ContractRootDomain + return genesis.ContractMigrationAdmin } // Get reference on migrationdaemon contract by migration member. func GetMigrationDaemon(migrationMember insolar.Reference) (insolar.Reference, error) { - return genesisrefs.ContractMigrationMap[migrationMember], nil + return genesis.ContractMigrationMap[migrationMember], nil } // Check member is migration daemon member or not func IsMigrationDaemonMember(member insolar.Reference) bool { - for _, mDaemonMember := range genesisrefs.ContractMigrationDaemonMembers { + for _, mDaemonMember := range genesis.ContractMigrationDaemonMembers { if mDaemonMember.Equal(member) { return true } diff --git a/application/builtin/contract/deposit/deposit.go b/application/builtin/contract/deposit/deposit.go index ed545f9..3ce4bda 100644 --- a/application/builtin/contract/deposit/deposit.go +++ b/application/builtin/contract/deposit/deposit.go @@ -22,7 +22,7 @@ import ( "github.com/insolar/mainnet/application/builtin/proxy/member" "github.com/insolar/mainnet/application/builtin/proxy/migrationdaemon" "github.com/insolar/mainnet/application/builtin/proxy/wallet" - "github.com/insolar/mainnet/application/genesisrefs" + "github.com/insolar/mainnet/application/genesis" ) const ( @@ -204,7 +204,7 @@ func (d *Deposit) Confirm( if err != nil { return errors.Wrap(err, "failed to get wallet") } - ok, maDeposit, _ := wallet.GetObject(*walletRef).FindDeposit(genesisrefs.FundsDepositName) + ok, maDeposit, _ := wallet.GetObject(*walletRef).FindDeposit(genesis.FundsDepositName) if !ok { return fmt.Errorf("failed to find source deposit - %s", walletRef.String()) } diff --git a/application/builtin/contract/member/member.go b/application/builtin/contract/member/member.go index ab2fce7..5dc16c6 100644 --- a/application/builtin/contract/member/member.go +++ b/application/builtin/contract/member/member.go @@ -27,7 +27,7 @@ import ( "github.com/insolar/mainnet/application/builtin/proxy/migrationdaemon" "github.com/insolar/mainnet/application/builtin/proxy/rootdomain" "github.com/insolar/mainnet/application/builtin/proxy/wallet" - "github.com/insolar/mainnet/application/genesisrefs" + "github.com/insolar/mainnet/application/genesis" ) const ( @@ -475,7 +475,7 @@ func (m *Member) coinBurnCall(params map[string]interface{}) (interface{}, error // Platform methods. func (m *Member) registerNode(public string, role string) (interface{}, error) { - root := genesisrefs.ContractRootMember + root := genesis.ContractRootMember if m.GetReference() != root { return "", fmt.Errorf("only root member can register node") } @@ -540,7 +540,7 @@ func (m *Member) contractCreateMemberCall(key string) (*CreateResponse, error) { func (m *Member) contractCreateMember(key string, migrationAddress string) (*member.Member, error) { - rootDomain := rootdomain.GetObject(appfoundation.GetRootDomain()) + rootDomain := rootdomain.GetObject(genesis.GetRootDomain()) created, err := m.createMember(key, migrationAddress) if err != nil { @@ -560,19 +560,19 @@ func (m *Member) createMember(key string, migrationAddress string) (*member.Memb } aHolder := account.New(ACCOUNT_START_VALUE) - accountRef, err := aHolder.AsChild(appfoundation.GetRootDomain()) + accountRef, err := aHolder.AsChild(genesis.GetRootDomain()) if err != nil { return nil, fmt.Errorf("failed to create account for member: %s", err.Error()) } wHolder := wallet.New(accountRef.Reference) - walletRef, err := wHolder.AsChild(appfoundation.GetRootDomain()) + walletRef, err := wHolder.AsChild(genesis.GetRootDomain()) if err != nil { return nil, fmt.Errorf("failed to create wallet for member: %s", err.Error()) } memberHolder := member.New(key, migrationAddress, walletRef.Reference) - created, err := memberHolder.AsChild(appfoundation.GetRootDomain()) + created, err := memberHolder.AsChild(genesis.GetRootDomain()) if err != nil { return nil, fmt.Errorf("failed to save as child: %s", err.Error()) } @@ -591,7 +591,7 @@ type GetResponse struct { } func (m *Member) memberGet(publicKey string) (interface{}, error) { - rootDomain := rootdomain.GetObject(appfoundation.GetRootDomain()) + rootDomain := rootdomain.GetObject(genesis.GetRootDomain()) ref, err := rootDomain.GetMemberByPublicKey(publicKey) if err != nil { return nil, fmt.Errorf("failed to get reference by public key: %s", err.Error()) diff --git a/application/cmd/insolar/bootstrap.go b/application/cmd/insolar/bootstrap.go index f15b23b..c6a320e 100644 --- a/application/cmd/insolar/bootstrap.go +++ b/application/cmd/insolar/bootstrap.go @@ -8,10 +8,9 @@ package main import ( "context" - "github.com/spf13/cobra" - basebootstrap "github.com/insolar/insolar/applicationbase/bootstrap" - "github.com/insolar/mainnet/application/bootstrap" + "github.com/insolar/mainnet/application/genesis/contracts" + "github.com/spf13/cobra" ) func bootstrapCommand() *cobra.Command { @@ -26,7 +25,7 @@ func bootstrapCommand() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { ctx := context.Background() - contractsConfig, err := bootstrap.CreateGenesisContractsConfig(ctx, configPath) + contractsConfig, err := contracts.CreateGenesisContractsConfig(ctx, configPath) check("failed to create genesis contracts config", err) config, err := basebootstrap.ParseConfig(configPath) diff --git a/application/cmd/insolar/create_default_configs.go b/application/cmd/insolar/create_default_configs.go index 5a86278..6ad6898 100644 --- a/application/cmd/insolar/create_default_configs.go +++ b/application/cmd/insolar/create_default_configs.go @@ -14,7 +14,7 @@ import ( bootstrapbase "github.com/insolar/insolar/applicationbase/bootstrap" pulsewatcher "github.com/insolar/insolar/cmd/pulsewatcher/config" "github.com/insolar/insolar/configuration" - "github.com/insolar/mainnet/application/bootstrap" + "github.com/insolar/mainnet/application/genesis/contracts" ) func writePulsarConfig(outputDir string) { @@ -36,7 +36,7 @@ func writeBootstrapConfig(outputDir string) { panic(err) } - rawApp, err := yaml.Marshal(bootstrap.ContractsConfig{}) + rawApp, err := yaml.Marshal(contracts.ContractsConfig{}) if err != nil { panic(err) } diff --git a/application/cmd/insolard/main.go b/application/cmd/insolard/main.go new file mode 100644 index 0000000..1f38c4c --- /dev/null +++ b/application/cmd/insolard/main.go @@ -0,0 +1,36 @@ +// Copyright 2020 Insolar Network Ltd. +// All rights reserved. +// This material is licensed under the Insolar License version 1.0, +// available at https://github.com/insolar/insolar/blob/master/LICENSE.md. + +package main + +import ( + "github.com/pkg/errors" + + "github.com/insolar/insolar/insolard" + "github.com/insolar/insolar/log" + "github.com/insolar/insolar/logicrunner/builtin" + "github.com/insolar/mainnet/application/appfoundation" + appbuiltin "github.com/insolar/mainnet/application/builtin" + "github.com/insolar/mainnet/application/genesis" + "github.com/insolar/mainnet/application/genesis/contracts" +) + +func main() { + parentDomain := genesis.GenesisNameRootDomain + scVersion := int64(appfoundation.AllowedVersionSmartContract) + builtinContracts := builtin.BuiltinContracts{ + CodeRegistry: appbuiltin.InitializeContractMethods(), + CodeRefRegistry: appbuiltin.InitializeCodeRefs(), + CodeDescriptors: appbuiltin.InitializeCodeDescriptors(), + PrototypeDescriptors: appbuiltin.InitializePrototypeDescriptors(), + } + apiOptions, err := genesis.InitAPIOptions() + if err != nil { + log.Fatal(errors.Wrap(err, "failed to get API info response")) + } + initStates := contracts.InitStates + + insolard.RunInsolarNode(parentDomain, scVersion, apiOptions, initStates, builtinContracts) +} diff --git a/application/functest/fund_test.go b/application/functest/fund_test.go index 0d50442..365899c 100644 --- a/application/functest/fund_test.go +++ b/application/functest/fund_test.go @@ -17,14 +17,12 @@ import ( "github.com/insolar/insolar/applicationbase/testutils/launchnet" "github.com/insolar/insolar/applicationbase/testutils/testrequest" - - "github.com/insolar/mainnet/application" - "github.com/insolar/mainnet/application/genesisrefs" + "github.com/insolar/mainnet/application/genesis" ) func TestFoundationMemberCreate(t *testing.T) { for _, m := range Foundation { - err := verifyFundsMembersAndDeposits(t, m, application.FoundationDistributionAmount) + err := verifyFundsMembersAndDeposits(t, m, genesis.FoundationDistributionAmount) if err != nil { require.NoError(t, err) } @@ -33,7 +31,7 @@ func TestFoundationMemberCreate(t *testing.T) { func TestEnterpriseMemberCreate(t *testing.T) { for _, m := range Enterprise { - err := verifyFundsMembersExist(t, m, application.EnterpriseDistributionAmount) + err := verifyFundsMembersExist(t, m, genesis.EnterpriseDistributionAmount) if err != nil { require.NoError(t, err) } @@ -42,9 +40,9 @@ func TestEnterpriseMemberCreate(t *testing.T) { func TestNetworkIncentivesMemberCreate(t *testing.T) { // for speed up test check only last member - m := NetworkIncentives[application.GenesisAmountNetworkIncentivesMembers-1] + m := NetworkIncentives[genesis.GenesisAmountNetworkIncentivesMembers-1] - err := verifyFundsMembersAndDeposits(t, m, application.NetworkIncentivesDistributionAmount) + err := verifyFundsMembersAndDeposits(t, m, genesis.NetworkIncentivesDistributionAmount) if err != nil { require.NoError(t, err) } @@ -52,7 +50,7 @@ func TestNetworkIncentivesMemberCreate(t *testing.T) { func TestApplicationIncentivesMemberCreate(t *testing.T) { for _, m := range ApplicationIncentives { - err := verifyFundsMembersAndDeposits(t, m, application.AppIncentivesDistributionAmount) + err := verifyFundsMembersAndDeposits(t, m, genesis.AppIncentivesDistributionAmount) if err != nil { require.NoError(t, err) } @@ -64,7 +62,7 @@ func checkBalanceAndDepositFewTimes(t *testing.T, m *AppUser, expectedBalance st var depositStr string for i := 0; i < times; i++ { balance, deposits := getBalanceAndDepositsNoErr(t, m, m.Ref) - depositStr = deposits[genesisrefs.FundsDepositName].(map[string]interface{})["balance"].(string) + depositStr = deposits[genesis.FundsDepositName].(map[string]interface{})["balance"].(string) if balance.String() == expectedBalance && depositStr == expectedDeposit { return } @@ -78,7 +76,7 @@ func checkBalanceAndDepositFewTimes(t *testing.T, m *AppUser, expectedBalance st func TestNetworkIncentivesTransferDeposit(t *testing.T) { // for speed up test check only last member - lastIdx := application.GenesisAmountNetworkIncentivesMembers - 1 + lastIdx := genesis.GenesisAmountNetworkIncentivesMembers - 1 m := NetworkIncentives[lastIdx] res2, err := testrequest.SignedRequest(t, launchnet.TestRPCUrlPublic, m, "member.get", nil) @@ -88,10 +86,10 @@ func TestNetworkIncentivesTransferDeposit(t *testing.T) { require.True(t, ok, fmt.Sprintf("failed to decode: expected map[string]interface{}, got %T", res2)) _, err = testrequest.SignedRequest(t, launchnet.TestRPCUrlPublic, m, - "deposit.transfer", map[string]interface{}{"amount": "100", "ethTxHash": genesisrefs.FundsDepositName}, + "deposit.transfer", map[string]interface{}{"amount": "100", "ethTxHash": genesis.FundsDepositName}, ) require.NoError(t, err) - depositAmount, ok := new(big.Int).SetString(application.NetworkIncentivesDistributionAmount, 10) + depositAmount, ok := new(big.Int).SetString(genesis.NetworkIncentivesDistributionAmount, 10) require.True(t, ok, "can't parse NetworkIncentivesDistributionAmount") checkBalanceAndDepositFewTimes(t, m, "100", depositAmount.Sub(depositAmount, big.NewInt(100)).String()) } @@ -105,10 +103,10 @@ func TestApplicationIncentivesTransferDeposit(t *testing.T) { require.True(t, ok, fmt.Sprintf("failed to decode: expected map[string]interface{}, got %T", res2)) _, err = testrequest.SignedRequest(t, launchnet.TestRPCUrlPublic, m, - "deposit.transfer", map[string]interface{}{"amount": "100", "ethTxHash": genesisrefs.FundsDepositName}, + "deposit.transfer", map[string]interface{}{"amount": "100", "ethTxHash": genesis.FundsDepositName}, ) require.NoError(t, err) - depositAmount, ok := new(big.Int).SetString(application.AppIncentivesDistributionAmount, 10) + depositAmount, ok := new(big.Int).SetString(genesis.AppIncentivesDistributionAmount, 10) require.True(t, ok, "can't parse AppIncentivesDistributionAmount") checkBalanceAndDepositFewTimes(t, m, "100", depositAmount.Sub(depositAmount, big.NewInt(100)).String()) } @@ -123,10 +121,10 @@ func TestFoundationTransferDeposit(t *testing.T) { require.True(t, ok, fmt.Sprintf("failed to decode: expected map[string]interface{}, got %T", res2)) _, err = testrequest.SignedRequest(t, launchnet.TestRPCUrlPublic, m, - "deposit.transfer", map[string]interface{}{"amount": "100", "ethTxHash": genesisrefs.FundsDepositName}, + "deposit.transfer", map[string]interface{}{"amount": "100", "ethTxHash": genesis.FundsDepositName}, ) require.NoError(t, err) - depositAmount, ok := new(big.Int).SetString(application.FoundationDistributionAmount, 10) + depositAmount, ok := new(big.Int).SetString(genesis.FoundationDistributionAmount, 10) require.True(t, ok, "can't parse FoundationDistributionAmount") checkBalanceAndDepositFewTimes(t, m, "100", depositAmount.Sub(depositAmount, big.NewInt(100)).String()) } @@ -142,14 +140,14 @@ func TestMigrationDaemonTransferDeposit(t *testing.T) { m.Ref = decodedRes2["reference"].(string) oldBalance, deposits := getBalanceAndDepositsNoErr(t, m, m.Ref) - oldDepositStr := deposits[genesisrefs.FundsDepositName].(map[string]interface{})["balance"].(string) + oldDepositStr := deposits[genesis.FundsDepositName].(map[string]interface{})["balance"].(string) _, err = testrequest.SignedRequest(t, launchnet.TestRPCUrlPublic, m, - "deposit.transfer", map[string]interface{}{"amount": "100", "ethTxHash": genesisrefs.FundsDepositName}, + "deposit.transfer", map[string]interface{}{"amount": "100", "ethTxHash": genesis.FundsDepositName}, ) require.NoError(t, err) newBalance, newDeposits := getBalanceAndDepositsNoErr(t, m, m.Ref) - newDepositStr := newDeposits[genesisrefs.FundsDepositName].(map[string]interface{})["balance"].(string) + newDepositStr := newDeposits[genesis.FundsDepositName].(map[string]interface{})["balance"].(string) amount := int64(100) require.Equal(t, oldBalance.Add(oldBalance, big.NewInt(amount)).String(), newBalance.String()) oldDeposit, ok := new(big.Int).SetString(oldDepositStr, 10) diff --git a/application/functest/launchnet.go b/application/functest/launchnet.go index d3c2d5d..d47a72f 100644 --- a/application/functest/launchnet.go +++ b/application/functest/launchnet.go @@ -15,7 +15,7 @@ import ( "github.com/pkg/errors" "github.com/insolar/insolar/applicationbase/testutils/launchnet" - "github.com/insolar/mainnet/application" + "github.com/insolar/mainnet/application/genesis" "github.com/insolar/mainnet/application/sdk" ) @@ -23,10 +23,10 @@ const insolarRootMemberKeys = "root_member_keys.json" const insolarMigrationAdminMemberKeys = "migration_admin_member_keys.json" const insolarFeeMemberKeys = "fee_member_keys.json" -var ApplicationIncentives [application.GenesisAmountApplicationIncentivesMembers]*AppUser -var NetworkIncentives [application.GenesisAmountNetworkIncentivesMembers]*AppUser -var Enterprise [application.GenesisAmountEnterpriseMembers]*AppUser -var Foundation [application.GenesisAmountFoundationMembers]*AppUser +var ApplicationIncentives [genesis.GenesisAmountApplicationIncentivesMembers]*AppUser +var NetworkIncentives [genesis.GenesisAmountNetworkIncentivesMembers]*AppUser +var Enterprise [genesis.GenesisAmountEnterpriseMembers]*AppUser +var Foundation [genesis.GenesisAmountFoundationMembers]*AppUser var AppPath = []string{"insolar", "mainnet"} @@ -34,7 +34,7 @@ var info *sdk.InfoResponse var Root AppUser var MigrationAdmin AppUser var FeeMember AppUser -var MigrationDaemons [application.GenesisAmountMigrationDaemonMembers]*AppUser +var MigrationDaemons [genesis.GenesisAmountMigrationDaemonMembers]*AppUser type AppUser struct { Ref string @@ -136,7 +136,7 @@ func LoadAllMembersKeys() error { MigrationDaemons[i] = &md } - for i := 0; i < application.GenesisAmountApplicationIncentivesMembers; i++ { + for i := 0; i < genesis.GenesisAmountApplicationIncentivesMembers; i++ { path, err := launchnet.LaunchnetPath(AppPath, "configs", "application_incentives_"+strconv.Itoa(i)+"_member_keys.json") if err != nil { return err @@ -149,7 +149,7 @@ func LoadAllMembersKeys() error { ApplicationIncentives[i] = &md } - for i := 0; i < application.GenesisAmountNetworkIncentivesMembers; i++ { + for i := 0; i < genesis.GenesisAmountNetworkIncentivesMembers; i++ { path, err := launchnet.LaunchnetPath(AppPath, "configs", "network_incentives_"+strconv.Itoa(i)+"_member_keys.json") if err != nil { return err @@ -162,7 +162,7 @@ func LoadAllMembersKeys() error { NetworkIncentives[i] = &md } - for i := 0; i < application.GenesisAmountFoundationMembers; i++ { + for i := 0; i < genesis.GenesisAmountFoundationMembers; i++ { path, err := launchnet.LaunchnetPath(AppPath, "configs", "foundation_"+strconv.Itoa(i)+"_member_keys.json") if err != nil { return err @@ -175,7 +175,7 @@ func LoadAllMembersKeys() error { Foundation[i] = &md } - for i := 0; i < application.GenesisAmountEnterpriseMembers; i++ { + for i := 0; i < genesis.GenesisAmountEnterpriseMembers; i++ { path, err := launchnet.LaunchnetPath(AppPath, "configs", "enterprise_"+strconv.Itoa(i)+"_member_keys.json") if err != nil { return err diff --git a/application/functest/migration_add_addresses_test.go b/application/functest/migration_add_addresses_test.go index f7f705e..31115ce 100644 --- a/application/functest/migration_add_addresses_test.go +++ b/application/functest/migration_add_addresses_test.go @@ -18,8 +18,8 @@ import ( "github.com/insolar/insolar/applicationbase/testutils/launchnet" "github.com/insolar/insolar/insolar/defaults" - "github.com/insolar/mainnet/application/bootstrap" "github.com/insolar/mainnet/application/cmd/insolar/insolarcmd" + "github.com/insolar/mainnet/application/genesis/contracts" ) func TestAddMigrationAddresses(t *testing.T) { @@ -29,7 +29,7 @@ func TestAddMigrationAddresses(t *testing.T) { t.Skip(extraAddrsDir, "extra addresses dir already exists") } - bootCfg, err := bootstrap.ParseContractsConfig(filepath.Join(defaults.LaunchnetDir(), "bootstrap.yaml")) + bootCfg, err := contracts.ParseContractsConfig(filepath.Join(defaults.LaunchnetDir(), "bootstrap.yaml")) require.NoError(t, err, "bootstrap config parse") shardsCount := bootCfg.MAShardCount diff --git a/application/functest/send_money_test.go b/application/functest/send_money_test.go index 64f16d5..a6bb16e 100644 --- a/application/functest/send_money_test.go +++ b/application/functest/send_money_test.go @@ -19,7 +19,7 @@ import ( "github.com/insolar/insolar/applicationbase/testutils/testrequest" "github.com/insolar/insolar/insolar/gen" - "github.com/insolar/mainnet/application/genesisrefs" + "github.com/insolar/mainnet/application/genesis" ) const times = 5 @@ -290,10 +290,10 @@ func TestTransferMoneyFromNotMemberRef(t *testing.T) { firstMember := createMember(t) secondMember := createMember(t) // Broke member to request object with prototype with no 'Call' method - firstMember.Ref = genesisrefs.ContractCostCenter.String() + firstMember.Ref = genesis.ContractCostCenter.String() amountStr := "10" _, _, err := testrequest.MakeSignedRequest(launchnet.TestRPCUrlPublic, firstMember, "member.transfer", - map[string]interface{}{"amount": amountStr, "toMemberReference": secondMember.Ref}) + map[string]interface{}{"amount": amountStr, "toMemberReference": secondMember.Ref}) data := checkConvertRequesterError(t, err).Data require.Contains(t, data.Trace, "failed to find contracts method") } diff --git a/application/functest/test_utils.go b/application/functest/test_utils.go index 7474902..0f78430 100644 --- a/application/functest/test_utils.go +++ b/application/functest/test_utils.go @@ -17,15 +17,13 @@ import ( "testing" "time" + "github.com/insolar/insolar/api/requester" + "github.com/insolar/insolar/applicationbase/testutils/launchnet" "github.com/insolar/insolar/applicationbase/testutils/testrequest" "github.com/insolar/insolar/applicationbase/testutils/testresponse" "github.com/insolar/insolar/insolar/secrets" "github.com/insolar/insolar/logicrunner/builtin/foundation" - "github.com/insolar/mainnet/application/genesisrefs" - - "github.com/insolar/insolar/api/requester" - "github.com/insolar/insolar/applicationbase/testutils/launchnet" - + "github.com/insolar/mainnet/application/genesis" "github.com/stretchr/testify/require" "github.com/pkg/errors" @@ -95,7 +93,7 @@ func getBalanceNoErr(t *testing.T, caller *AppUser, reference string) *big.Int { func getAdminDepositBalance(t *testing.T, caller *AppUser, reference string) (*big.Int, error) { _, deposits := getBalanceAndDepositsNoErr(t, caller, reference) - mapd, ok := deposits[genesisrefs.FundsDepositName].(map[string]interface{}) + mapd, ok := deposits[genesis.FundsDepositName].(map[string]interface{}) if !ok { return nil, fmt.Errorf("can't parse deposit") } diff --git a/cmd/insolard/api.go b/application/genesis/api.go similarity index 85% rename from cmd/insolard/api.go rename to application/genesis/api.go index 04f62a2..98a8599 100644 --- a/cmd/insolard/api.go +++ b/application/genesis/api.go @@ -3,28 +3,27 @@ // This material is licensed under the Insolar License version 1.0, // available at https://github.com/insolar/mainnet/blob/master/LICENSE.md. -package main +package genesis import ( "github.com/insolar/insolar/api" - "github.com/insolar/mainnet/application/genesisrefs" "github.com/pkg/errors" ) // initAPIInfoResponse creates application-specific data, // that will be included in response from /admin-api/rpc#network.getInfo func initAPIInfoResponse() (map[string]interface{}, error) { - rootDomain := genesisrefs.ContractRootDomain + rootDomain := ContractRootDomain if rootDomain.IsEmpty() { return nil, errors.New("rootDomain ref is nil") } - rootMember := genesisrefs.ContractRootMember + rootMember := ContractRootMember if rootMember.IsEmpty() { return nil, errors.New("rootMember ref is nil") } - migrationDaemonMembers := genesisrefs.ContractMigrationDaemonMembers + migrationDaemonMembers := ContractMigrationDaemonMembers migrationDaemonMembersStrs := make([]string, 0) for _, r := range migrationDaemonMembers { if r.IsEmpty() { @@ -33,11 +32,11 @@ func initAPIInfoResponse() (map[string]interface{}, error) { migrationDaemonMembersStrs = append(migrationDaemonMembersStrs, r.String()) } - migrationAdminMember := genesisrefs.ContractMigrationAdminMember + migrationAdminMember := ContractMigrationAdminMember if migrationAdminMember.IsEmpty() { return nil, errors.New("migration admin member ref is nil") } - feeMember := genesisrefs.ContractFeeMember + feeMember := ContractFeeMember if feeMember.IsEmpty() { return nil, errors.New("feeMember ref is nil") } @@ -51,7 +50,7 @@ func initAPIInfoResponse() (map[string]interface{}, error) { } // initAPIOptions creates options object, that contains application-specific settings for api component. -func initAPIOptions() (api.Options, error) { +func InitAPIOptions() (api.Options, error) { apiInfoResponse, err := initAPIInfoResponse() if err != nil { return api.Options{}, err @@ -82,7 +81,7 @@ func initAPIOptions() (api.Options, error) { AdminContractMethods: adminContractMethods, ContractMethods: contractMethods, InfoResponse: apiInfoResponse, - RootReference: genesisrefs.ContractRootMember, + RootReference: ContractRootMember, ProxyToRootMethods: proxyToRootMethods, }, nil } diff --git a/application/bootstrap/bootstrap.go b/application/genesis/contracts/bootstrap.go similarity index 93% rename from application/bootstrap/bootstrap.go rename to application/genesis/contracts/bootstrap.go index d3ee906..cfe17e1 100644 --- a/application/bootstrap/bootstrap.go +++ b/application/genesis/contracts/bootstrap.go @@ -3,7 +3,7 @@ // This material is licensed under the Insolar License version 1.0, // available at https://github.com/insolar/mainnet/blob/master/LICENSE.md. -package bootstrap +package contracts import ( "bytes" @@ -20,8 +20,8 @@ import ( "github.com/insolar/insolar/insolar/secrets" "github.com/insolar/insolar/instrumentation/inslogger" "github.com/insolar/insolar/logicrunner/builtin/foundation" - "github.com/insolar/mainnet/application" "github.com/insolar/mainnet/application/appfoundation" + "github.com/insolar/mainnet/application/genesis" ) func readMigrationAddresses(config *ContractsConfig) ([][]string, error) { @@ -79,7 +79,7 @@ func CreateGenesisContractsConfig(ctx context.Context, configFile string) (map[s return nil, errors.Wrap(err, "couldn't get migration admin keys") } migrationDaemonPublicKeys := []string{} - for i := 0; i < application.GenesisAmountMigrationDaemonMembers; i++ { + for i := 0; i < genesis.GenesisAmountMigrationDaemonMembers; i++ { k, err := secrets.GetPublicKeyFromFile(config.MembersKeysDir + GetMigrationDaemonPath(i)) if err != nil { return nil, errors.Wrap(err, "couldn't get migration daemon keys") @@ -88,7 +88,7 @@ func CreateGenesisContractsConfig(ctx context.Context, configFile string) (map[s } networkIncentivesPublicKeys := []string{} - for i := 0; i < application.GenesisAmountNetworkIncentivesMembers; i++ { + for i := 0; i < genesis.GenesisAmountNetworkIncentivesMembers; i++ { k, err := secrets.GetPublicKeyFromFile( filepath.Join(config.MembersKeysDir, GetFundPath(i, "network_incentives_"))) if err != nil { @@ -98,7 +98,7 @@ func CreateGenesisContractsConfig(ctx context.Context, configFile string) (map[s } applicationIncentivesPublicKeys := []string{} - for i := 0; i < application.GenesisAmountApplicationIncentivesMembers; i++ { + for i := 0; i < genesis.GenesisAmountApplicationIncentivesMembers; i++ { k, err := secrets.GetPublicKeyFromFile( filepath.Join(config.MembersKeysDir, GetFundPath(i, "application_incentives_"))) if err != nil { @@ -108,7 +108,7 @@ func CreateGenesisContractsConfig(ctx context.Context, configFile string) (map[s } foundationPublicKeys := []string{} - for i := 0; i < application.GenesisAmountFoundationMembers; i++ { + for i := 0; i < genesis.GenesisAmountFoundationMembers; i++ { k, err := secrets.GetPublicKeyFromFile( filepath.Join(config.MembersKeysDir, GetFundPath(i, "foundation_"))) if err != nil { @@ -118,7 +118,7 @@ func CreateGenesisContractsConfig(ctx context.Context, configFile string) (map[s } enterprisePublicKeys := []string{} - for i := 0; i < application.GenesisAmountEnterpriseMembers; i++ { + for i := 0; i < genesis.GenesisAmountEnterpriseMembers; i++ { k, err := secrets.GetPublicKeyFromFile( filepath.Join(config.MembersKeysDir, GetFundPath(i, "enterprise_"))) if err != nil { diff --git a/application/bootstrap/config.go b/application/genesis/contracts/config.go similarity index 99% rename from application/bootstrap/config.go rename to application/genesis/contracts/config.go index 7169ced..a3476c3 100644 --- a/application/bootstrap/config.go +++ b/application/genesis/contracts/config.go @@ -3,7 +3,7 @@ // This material is licensed under the Insolar License version 1.0, // available at https://github.com/insolar/mainnet/blob/master/LICENSE.md. -package bootstrap +package contracts import ( "github.com/pkg/errors" diff --git a/application/genesis/contracts/contracts.go b/application/genesis/contracts/contracts.go new file mode 100644 index 0000000..4cbdbef --- /dev/null +++ b/application/genesis/contracts/contracts.go @@ -0,0 +1,477 @@ +// Copyright 2020 Insolar Network Ltd. +// All rights reserved. +// This material is licensed under the Insolar License version 1.0, +// available at https://github.com/insolar/insolar/blob/master/LICENSE.md. + +package contracts + +import ( + "encoding/json" + "fmt" + "github.com/insolar/insolar/applicationbase/genesis" + "github.com/insolar/mainnet/application/builtin/contract/account" + "github.com/insolar/mainnet/application/builtin/contract/costcenter" + "github.com/insolar/mainnet/application/builtin/contract/deposit" + "github.com/insolar/mainnet/application/builtin/contract/migrationadmin" + "github.com/insolar/mainnet/application/builtin/contract/migrationdaemon" + "github.com/insolar/mainnet/application/builtin/contract/migrationshard" + "github.com/insolar/mainnet/application/builtin/contract/pkshard" + "github.com/insolar/mainnet/application/builtin/contract/rootdomain" + "github.com/insolar/mainnet/application/builtin/contract/wallet" + "github.com/pkg/errors" + "io/ioutil" + "time" + + "github.com/insolar/insolar/insolar" + "github.com/insolar/insolar/logicrunner/builtin/foundation" + "github.com/insolar/insolar/pulse" + "github.com/insolar/mainnet/application/appfoundation" + + "github.com/insolar/insolar/log" + "github.com/insolar/mainnet/application/builtin/contract/member" + . "github.com/insolar/mainnet/application/genesis" +) + +const ( + XNS = "XNS" + MigrationDaemonUnholdDate = 1596456000 // 03.08.2020 12-00-00 + MigrationDaemonVesting = 0 + MigrationDaemonVestingStep = 0 + + NetworkIncentivesUnholdStartDate = 1583020800 // 01.03.2020 00-00-00 + NetworkIncentivesVesting = 0 + NetworkIncentivesVestingStep = 0 + + ApplicationIncentivesUnholdStartDate = 1609459200 // 01.01.2021 00-00-00 + ApplicationIncentivesVesting = 0 + ApplicationIncentivesVestingStep = 0 + + FoundationUnholdStartDate = 1609459200 // 01.01.2021 00-00-00 + FoundationVestingPeriod = 0 + FoundationVestingStep = 0 +) + +func InitStates(genesisConfigPath string) ([]genesis.ContractState, error) { + b, err := ioutil.ReadFile(genesisConfigPath) + if err != nil { + log.Fatalf("failed to load genesis configuration from file: %v", genesisConfigPath) + } + var config struct { + ContractsConfig GenesisContractsConfig + } + err = json.Unmarshal(b, &config) + if err != nil { + log.Fatalf("failed to parse genesis configuration from file: %v", genesisConfigPath) + } + + contractsConfig := config.ContractsConfig + + migrationAccounts := make(foundation.StableMap) + migrationAccounts[XNS] = ContractMigrationAccount.String() + + migrationDeposits := make(foundation.StableMap) + migrationDeposits[FundsDepositName] = ContractMigrationDeposit.String() + + ContractMigrationAddressShardRefs(contractsConfig.MAShardCount) + ContractPublicKeyShardRefs(contractsConfig.PKShardCount) + + // Hint: order matters, because of dependency contracts on each other. + states := []genesis.ContractState{ + rootDomain(contractsConfig.PKShardCount), + GetMemberGenesisContractState(contractsConfig.RootPublicKey, GenesisNameRootMember, GenesisNameRootDomain, ContractRootWallet), + GetMemberGenesisContractState(contractsConfig.MigrationAdminPublicKey, GenesisNameMigrationAdminMember, GenesisNameRootDomain, ContractMigrationWallet), + GetMemberGenesisContractState(contractsConfig.FeePublicKey, GenesisNameFeeMember, GenesisNameRootDomain, ContractFeeWallet), + + GetWalletGenesisContractState(GenesisNameRootWallet, GenesisNameRootDomain, ContractRootAccount), + GetPreWalletGenesisContractState(GenesisNameMigrationAdminWallet, GenesisNameRootDomain, migrationAccounts, migrationDeposits), + GetWalletGenesisContractState(GenesisNameFeeWallet, GenesisNameRootDomain, ContractFeeAccount), + + GetAccountGenesisContractState(contractsConfig.RootBalance, GenesisNameRootAccount, GenesisNameRootDomain), + GetAccountGenesisContractState("0", GenesisNameMigrationAdminAccount, GenesisNameRootDomain), + GetAccountGenesisContractState("0", GenesisNameFeeAccount, GenesisNameRootDomain), + + GetDepositGenesisContractState( + contractsConfig.MDBalance, + MigrationDaemonVesting, + MigrationDaemonVestingStep, + appfoundation.Vesting2, + pulse.OfUnixTime(MigrationDaemonUnholdDate), // Unhold date + GenesisNameMigrationAdminDeposit, + GenesisNameRootDomain, + ), + GetMigrationAdminGenesisContractState(contractsConfig.LockupPeriodInPulses, contractsConfig.VestingPeriodInPulses, contractsConfig.VestingStepInPulses, contractsConfig.MAShardCount), + GetCostCenterGenesisContractState(), + } + + for i, key := range contractsConfig.MigrationDaemonPublicKeys { + states = append(states, GetMemberGenesisContractState(key, GenesisNameMigrationDaemonMembers[i], GenesisNameRootDomain, *insolar.NewEmptyReference())) + states = append(states, GetMigrationDaemonGenesisContractState(i)) + } + + for i, key := range contractsConfig.ApplicationIncentivesPublicKeys { + states = append(states, GetMemberGenesisContractState(key, GenesisNameApplicationIncentivesMembers[i], GenesisNameRootDomain, ContractApplicationIncentivesWallets[i])) + + states = append(states, GetAccountGenesisContractState("0", GenesisNameApplicationIncentivesAccounts[i], GenesisNameRootDomain)) + + unholdWithMonth := time.Unix(ApplicationIncentivesUnholdStartDate, 0).AddDate(0, i, 0).Unix() + + states = append(states, GetDepositGenesisContractState( + AppIncentivesDistributionAmount, + ApplicationIncentivesVesting, + ApplicationIncentivesVestingStep, + appfoundation.Vesting2, + pulse.OfUnixTime(unholdWithMonth), + GenesisNameApplicationIncentivesDeposits[i], + GenesisNameRootDomain, + )) + + membersAccounts := make(foundation.StableMap) + membersAccounts[XNS] = ContractApplicationIncentivesAccounts[i].String() + + membersDeposits := make(foundation.StableMap) + membersDeposits[FundsDepositName] = ContractApplicationIncentivesDeposits[i].String() + + states = append(states, GetPreWalletGenesisContractState( + GenesisNameApplicationIncentivesWallets[i], + GenesisNameRootDomain, + membersAccounts, + membersDeposits, + )) + } + + for i, key := range contractsConfig.NetworkIncentivesPublicKeys { + states = append(states, GetMemberGenesisContractState(key, GenesisNameNetworkIncentivesMembers[i], GenesisNameRootDomain, ContractNetworkIncentivesWallets[i])) + states = append(states, GetAccountGenesisContractState("0", GenesisNameNetworkIncentivesAccounts[i], GenesisNameRootDomain)) + + unholdWithMonth := time.Unix(NetworkIncentivesUnholdStartDate, 0).AddDate(0, i, 0).Unix() + + states = append(states, GetDepositGenesisContractState( + NetworkIncentivesDistributionAmount, + NetworkIncentivesVesting, + NetworkIncentivesVestingStep, + appfoundation.Vesting2, + pulse.OfUnixTime(unholdWithMonth), + GenesisNameNetworkIncentivesDeposits[i], + GenesisNameRootDomain, + )) + + membersAccounts := make(foundation.StableMap) + membersAccounts[XNS] = ContractNetworkIncentivesAccounts[i].String() + + membersDeposits := make(foundation.StableMap) + membersDeposits[FundsDepositName] = ContractNetworkIncentivesDeposits[i].String() + + states = append(states, GetPreWalletGenesisContractState( + GenesisNameNetworkIncentivesWallets[i], + GenesisNameRootDomain, + membersAccounts, + membersDeposits, + )) + } + + for i, key := range contractsConfig.FoundationPublicKeys { + states = append(states, GetMemberGenesisContractState(key, GenesisNameFoundationMembers[i], GenesisNameRootDomain, ContractFoundationWallets[i])) + states = append(states, GetAccountGenesisContractState("0", GenesisNameFoundationAccounts[i], GenesisNameRootDomain)) + + unholdWithMonth := time.Unix(FoundationUnholdStartDate, 0).AddDate(0, i, 0).Unix() + + states = append(states, GetDepositGenesisContractState( + FoundationDistributionAmount, + FoundationVestingPeriod, + FoundationVestingStep, + appfoundation.Vesting2, + pulse.OfUnixTime(unholdWithMonth), + GenesisNameFoundationDeposits[i], + GenesisNameRootDomain, + )) + + membersAccounts := make(foundation.StableMap) + membersAccounts[XNS] = ContractFoundationAccounts[i].String() + + membersDeposits := make(foundation.StableMap) + membersDeposits[FundsDepositName] = ContractFoundationDeposits[i].String() + + states = append(states, GetPreWalletGenesisContractState( + GenesisNameFoundationWallets[i], + GenesisNameRootDomain, + membersAccounts, + membersDeposits, + )) + } + + for i, key := range contractsConfig.EnterprisePublicKeys { + states = append(states, GetMemberGenesisContractState(key, GenesisNameEnterpriseMembers[i], GenesisNameRootDomain, ContractEnterpriseWallets[i])) + states = append(states, GetAccountGenesisContractState( + EnterpriseDistributionAmount, + GenesisNameEnterpriseAccounts[i], + GenesisNameRootDomain, + )) + + membersAccounts := make(foundation.StableMap) + membersAccounts[XNS] = ContractEnterpriseAccounts[i].String() + + membersDeposits := make(foundation.StableMap) + + states = append(states, GetPreWalletGenesisContractState( + GenesisNameEnterpriseWallets[i], + GenesisNameRootDomain, + membersAccounts, + membersDeposits, + )) + } + + if contractsConfig.PKShardCount <= 0 { + panic(fmt.Sprintf("[genesis] store contracts failed: setup pk_shard_count parameter, current value %v", contractsConfig.PKShardCount)) + } + if contractsConfig.VestingStepInPulses > 0 && contractsConfig.VestingPeriodInPulses%contractsConfig.VestingStepInPulses != 0 { + panic(fmt.Sprintf("[genesis] store contracts failed: vesting_pulse_period (%d) is not a multiple of vesting_pulse_step (%d)", contractsConfig.VestingPeriodInPulses, contractsConfig.VestingStepInPulses)) + } + + // Split genesis members by PK shards + var membersByPKShards []foundation.StableMap + for i := 0; i < contractsConfig.PKShardCount; i++ { + membersByPKShards = append(membersByPKShards, make(foundation.StableMap)) + } + trimmedRootPublicKey, err := foundation.ExtractCanonicalPublicKey(contractsConfig.RootPublicKey) + if err != nil { + panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", contractsConfig.RootPublicKey)) + } + index := foundation.GetShardIndex(trimmedRootPublicKey, contractsConfig.PKShardCount) + membersByPKShards[index][trimmedRootPublicKey] = ContractRootMember.String() + + trimmedMigrationAdminPublicKey, err := foundation.ExtractCanonicalPublicKey(contractsConfig.MigrationAdminPublicKey) + if err != nil { + panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", contractsConfig.MigrationAdminPublicKey)) + } + index = foundation.GetShardIndex(trimmedMigrationAdminPublicKey, contractsConfig.PKShardCount) + membersByPKShards[index][trimmedMigrationAdminPublicKey] = ContractMigrationAdminMember.String() + + trimmedFeeMemberPublicKey, err := foundation.ExtractCanonicalPublicKey(contractsConfig.FeePublicKey) + if err != nil { + panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", contractsConfig.FeePublicKey)) + } + index = foundation.GetShardIndex(trimmedFeeMemberPublicKey, contractsConfig.PKShardCount) + membersByPKShards[index][trimmedFeeMemberPublicKey] = ContractFeeMember.String() + + for i, key := range contractsConfig.MigrationDaemonPublicKeys { + trimmedMigrationDaemonPublicKey, err := foundation.ExtractCanonicalPublicKey(key) + if err != nil { + panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", key)) + } + index := foundation.GetShardIndex(trimmedMigrationDaemonPublicKey, contractsConfig.PKShardCount) + membersByPKShards[index][trimmedMigrationDaemonPublicKey] = ContractMigrationDaemonMembers[i].String() + } + + for i, key := range contractsConfig.NetworkIncentivesPublicKeys { + trimmedNetworkIncentivesPublicKey, err := foundation.ExtractCanonicalPublicKey(key) + if err != nil { + panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", key)) + } + index := foundation.GetShardIndex(trimmedNetworkIncentivesPublicKey, contractsConfig.PKShardCount) + membersByPKShards[index][trimmedNetworkIncentivesPublicKey] = ContractNetworkIncentivesMembers[i].String() + } + + for i, key := range contractsConfig.ApplicationIncentivesPublicKeys { + trimmedApplicationIncentivesPublicKey, err := foundation.ExtractCanonicalPublicKey(key) + if err != nil { + panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", key)) + } + index := foundation.GetShardIndex(trimmedApplicationIncentivesPublicKey, contractsConfig.PKShardCount) + membersByPKShards[index][trimmedApplicationIncentivesPublicKey] = ContractApplicationIncentivesMembers[i].String() + } + + for i, key := range contractsConfig.FoundationPublicKeys { + trimmedFoundationPublicKey, err := foundation.ExtractCanonicalPublicKey(key) + if err != nil { + panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", key)) + } + index := foundation.GetShardIndex(trimmedFoundationPublicKey, contractsConfig.PKShardCount) + membersByPKShards[index][trimmedFoundationPublicKey] = ContractFoundationMembers[i].String() + } + + for i, key := range contractsConfig.EnterprisePublicKeys { + trimmedEnterprisePublicKey, err := foundation.ExtractCanonicalPublicKey(key) + if err != nil { + panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", key)) + } + index := foundation.GetShardIndex(trimmedEnterprisePublicKey, contractsConfig.PKShardCount) + membersByPKShards[index][trimmedEnterprisePublicKey] = ContractEnterpriseMembers[i].String() + } + + // Append states for shards + for i, name := range ContractPublicKeyNameShards(contractsConfig.PKShardCount) { + states = append(states, GetPKShardGenesisContractState(name, membersByPKShards[i])) + } + for i, name := range ContractMigrationAddressNameShards(contractsConfig.MAShardCount) { + states = append(states, GetMigrationShardGenesisContractState(name, contractsConfig.MigrationAddresses[i])) + } + + return states, nil +} + +func rootDomain(pkShardCount int) genesis.ContractState { + + return genesis.ContractState{ + Name: GenesisNameRootDomain, + Prototype: GenesisNameRootDomain, + ParentName: "", + + Memory: genesis.MustGenMemory(&rootdomain.RootDomain{ + PublicKeyShards: ContractPublicKeyShards(pkShardCount), + }), + } +} + +func GetMemberGenesisContractState(publicKey string, name string, parent string, walletRef insolar.Reference) genesis.ContractState { + m, err := member.New(publicKey, "", *insolar.NewEmptyReference()) + if err != nil { + panic(fmt.Sprintf("'%s' member constructor failed", name)) + } + + m.Wallet = walletRef + + return genesis.ContractState{ + Name: name, + Prototype: GenesisNameMember, + ParentName: parent, + Memory: genesis.MustGenMemory(m), + } +} + +func GetWalletGenesisContractState(name string, parent string, accountRef insolar.Reference) genesis.ContractState { + w, err := wallet.New(accountRef) + if err != nil { + panic("failed to create ` " + name + "` wallet instance") + } + + return genesis.ContractState{ + Name: name, + Prototype: GenesisNameWallet, + ParentName: parent, + Memory: genesis.MustGenMemory(w), + } +} + +func GetPreWalletGenesisContractState(name string, parent string, accounts foundation.StableMap, deposits foundation.StableMap) genesis.ContractState { + return genesis.ContractState{ + Name: name, + Prototype: GenesisNameWallet, + ParentName: parent, + Memory: genesis.MustGenMemory(&wallet.Wallet{ + Accounts: accounts, + Deposits: deposits, + }), + } +} + +func GetAccountGenesisContractState(balance string, name string, parent string) genesis.ContractState { + w, err := account.New(balance) + if err != nil { + panic("failed to create ` " + name + "` account instance") + } + + return genesis.ContractState{ + Name: name, + Prototype: GenesisNameAccount, + ParentName: parent, + Memory: genesis.MustGenMemory(w), + } +} + +func GetCostCenterGenesisContractState() genesis.ContractState { + cc, err := costcenter.New(&ContractFeeMember) + if err != nil { + panic("failed to create cost center instance") + } + + return genesis.ContractState{ + Name: GenesisNameCostCenter, + Prototype: GenesisNameCostCenter, + ParentName: GenesisNameRootDomain, + Memory: genesis.MustGenMemory(cc), + } +} + +func GetPKShardGenesisContractState(name string, members foundation.StableMap) genesis.ContractState { + s, err := pkshard.New(members) + if err != nil { + panic(fmt.Sprintf("'%s' shard constructor failed", name)) + } + + return genesis.ContractState{ + Name: name, + Prototype: GenesisNamePKShard, + ParentName: GenesisNameRootDomain, + Memory: genesis.MustGenMemory(s), + } +} + +func GetMigrationShardGenesisContractState(name string, migrationAddresses []string) genesis.ContractState { + s, err := migrationshard.New(migrationAddresses) + if err != nil { + panic(fmt.Sprintf("'%s' shard constructor failed", name)) + } + + return genesis.ContractState{ + Name: name, + Prototype: GenesisNameMigrationShard, + ParentName: GenesisNameRootDomain, + Memory: genesis.MustGenMemory(s), + } +} + +func GetMigrationAdminGenesisContractState(lockup int64, vesting int64, vestingStep int64, maShardCount int) genesis.ContractState { + return genesis.ContractState{ + Name: GenesisNameMigrationAdmin, + Prototype: GenesisNameMigrationAdmin, + ParentName: GenesisNameRootDomain, + Memory: genesis.MustGenMemory(&migrationadmin.MigrationAdmin{ + MigrationAddressShards: ContractMigrationAddressShards(maShardCount), + MigrationAdminMember: ContractMigrationAdminMember, + VestingParams: &migrationadmin.VestingParams{ + Lockup: lockup, + Vesting: vesting, + VestingStep: vestingStep, + }, + }), + } +} + +func GetDepositGenesisContractState( + amount string, + vesting int64, + vestingStep int64, + vestingType appfoundation.VestingType, + pulseDepositUnHold insolar.PulseNumber, + name string, parent string, +) genesis.ContractState { + return genesis.ContractState{ + Name: name, + Prototype: GenesisNameDeposit, + ParentName: parent, + Memory: genesis.MustGenMemory(&deposit.Deposit{ + Balance: amount, + Amount: amount, + PulseDepositUnHold: pulseDepositUnHold, + VestingType: vestingType, + TxHash: FundsDepositName, + Lockup: int64(pulseDepositUnHold - pulse.MinTimePulse), + Vesting: vesting, + VestingStep: vestingStep, + IsConfirmed: true, + }), + } +} + +func GetMigrationDaemonGenesisContractState(numberMigrationDaemon int) genesis.ContractState { + + return genesis.ContractState{ + Name: GenesisNameMigrationDaemons[numberMigrationDaemon], + Prototype: GenesisNameMigrationDaemon, + ParentName: GenesisNameRootDomain, + Memory: genesis.MustGenMemory(&migrationdaemon.MigrationDaemon{ + IsActive: false, + MigrationDaemonMember: ContractMigrationDaemonMembers[numberMigrationDaemon], + }), + } +} diff --git a/application/genesis.go b/application/genesis/genesis.go similarity index 99% rename from application/genesis.go rename to application/genesis/genesis.go index df7b83a..328c4cb 100644 --- a/application/genesis.go +++ b/application/genesis/genesis.go @@ -3,7 +3,7 @@ // This material is licensed under the Insolar License version 1.0, // available at https://github.com/insolar/mainnet/blob/master/LICENSE.md. -package application +package genesis import ( "strconv" diff --git a/application/genesis/refs.go b/application/genesis/refs.go new file mode 100644 index 0000000..61dcb21 --- /dev/null +++ b/application/genesis/refs.go @@ -0,0 +1,331 @@ +// Copyright 2020 Insolar Network Ltd. +// All rights reserved. +// This material is licensed under the Insolar License version 1.0, +// available at https://github.com/insolar/insolar/blob/master/LICENSE.md. + +package genesis + +import ( + "github.com/insolar/insolar/applicationbase/genesisrefs" + "github.com/insolar/insolar/insolar" + "github.com/insolar/insolar/logicrunner/preprocessor" + "strconv" +) + +const ( + FundsDepositName = "genesis_deposit" +) + +var applicationPrototypes = map[string]insolar.Reference{ + GenesisNameRootDomain + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameRootDomain, 0), + GenesisNameRootMember + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMember, 0), + GenesisNameRootWallet + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameWallet, 0), + GenesisNameRootAccount + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameAccount, 0), + GenesisNameCostCenter + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameCostCenter, 0), + GenesisNameFeeMember + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMember, 0), + GenesisNameFeeWallet + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameWallet, 0), + GenesisNameFeeAccount + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameAccount, 0), + GenesisNameDeposit + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameDeposit, 0), + GenesisNameMember + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMember, 0), + GenesisNameMigrationAdminMember + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMember, 0), + GenesisNameMigrationAdmin + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMigrationAdmin, 0), + GenesisNameMigrationAdminWallet + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameWallet, 0), + GenesisNameMigrationAdminAccount + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameAccount, 0), + GenesisNameMigrationAdminDeposit + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameDeposit, 0), + GenesisNameWallet + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameWallet, 0), +} + +func init() { + for i, val := range applicationPrototypes { + genesisrefs.PredefinedPrototypes[i] = val + } + + for _, el := range GenesisNameMigrationDaemonMembers { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMember, 0) + } + + for _, el := range GenesisNameMigrationDaemons { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMigrationDaemon, 0) + } + + // Incentives Application + for _, el := range GenesisNameApplicationIncentivesMembers { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMember, 0) + } + for _, el := range GenesisNameApplicationIncentivesWallets { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameWallet, 0) + } + for _, el := range GenesisNameApplicationIncentivesAccounts { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameAccount, 0) + } + for _, el := range GenesisNameApplicationIncentivesDeposits { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameDeposit, 0) + } + + // Network Incentives + for _, el := range GenesisNameNetworkIncentivesMembers { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMember, 0) + } + for _, el := range GenesisNameNetworkIncentivesWallets { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameWallet, 0) + } + for _, el := range GenesisNameNetworkIncentivesAccounts { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameAccount, 0) + } + for _, el := range GenesisNameNetworkIncentivesDeposits { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameDeposit, 0) + } + + // Foundation + for _, el := range GenesisNameFoundationMembers { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMember, 0) + } + for _, el := range GenesisNameFoundationWallets { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameWallet, 0) + } + for _, el := range GenesisNameFoundationAccounts { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameAccount, 0) + } + for _, el := range GenesisNameFoundationDeposits { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameDeposit, 0) + } + + // Enterprise + for _, el := range GenesisNameEnterpriseMembers { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameMember, 0) + } + for _, el := range GenesisNameEnterpriseWallets { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameWallet, 0) + } + for _, el := range GenesisNameEnterpriseAccounts { + genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, GenesisNameAccount, 0) + } +} + +var ( + // ContractRootDomain is the root domain contract reference. + ContractRootDomain = genesisrefs.GenesisRef(GenesisNameRootDomain) + // ContractRootMember is the root member contract reference. + ContractRootMember = genesisrefs.GenesisRef(GenesisNameRootMember) + // ContractRootWallet is the root wallet contract reference. + ContractRootWallet = genesisrefs.GenesisRef(GenesisNameRootWallet) + // ContractRootAccount is the root account contract reference. + ContractRootAccount = genesisrefs.GenesisRef(GenesisNameRootAccount) + // ContractMigrationAdminMember is the migration admin member contract reference. + ContractMigrationAdminMember = genesisrefs.GenesisRef(GenesisNameMigrationAdminMember) + // ContractMigrationAdmin is the migration wallet contract reference. + ContractMigrationAdmin = genesisrefs.GenesisRef(GenesisNameMigrationAdmin) + // ContractMigrationWallet is the migration wallet contract reference. + ContractMigrationWallet = genesisrefs.GenesisRef(GenesisNameMigrationAdminWallet) + // ContractMigrationAccount is the migration account contract reference. + ContractMigrationAccount = genesisrefs.GenesisRef(GenesisNameMigrationAdminAccount) + // ContractMigrationDeposit is the migration deposit contract reference. + ContractMigrationDeposit = genesisrefs.GenesisRef(GenesisNameMigrationAdminDeposit) + // ContractDeposit is the deposit contract reference. + ContractDeposit = genesisrefs.GenesisRef(GenesisNameDeposit) + // ContractCostCenter is the cost center contract reference. + ContractCostCenter = genesisrefs.GenesisRef(GenesisNameCostCenter) + // ContractFeeMember is the fee member contract reference. + ContractFeeMember = genesisrefs.GenesisRef(GenesisNameFeeMember) + // ContractFeeWallet is the fee wallet contract reference. + ContractFeeWallet = genesisrefs.GenesisRef(GenesisNameFeeWallet) + // ContractFeeAccount is the fee account contract reference. + ContractFeeAccount = genesisrefs.GenesisRef(GenesisNameFeeAccount) + + // ContractMigrationDaemonMembers is the migration daemon members contracts references. + ContractMigrationDaemonMembers = func() (result [GenesisAmountMigrationDaemonMembers]insolar.Reference) { + for i, name := range GenesisNameMigrationDaemonMembers { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractMigrationMap where key is migration daemon member references and value related migration daemon contract + ContractMigrationMap = func() (result map[insolar.Reference]insolar.Reference) { + result = make(map[insolar.Reference]insolar.Reference) + for i := 0; i < GenesisAmountMigrationDaemonMembers; i++ { + result[genesisrefs.GenesisRef(GenesisNameMigrationDaemonMembers[i])] = genesisrefs.GenesisRef(GenesisNameMigrationDaemons[i]) + } + return + }() + + // ContractNetworkIncentivesMembers is the network incentives members contracts references. + ContractNetworkIncentivesMembers = func() (result [GenesisAmountNetworkIncentivesMembers]insolar.Reference) { + for i, name := range GenesisNameNetworkIncentivesMembers { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractApplicationIncentivesMembers is the application incentives members contracts references. + ContractApplicationIncentivesMembers = func() (result [GenesisAmountApplicationIncentivesMembers]insolar.Reference) { + for i, name := range GenesisNameApplicationIncentivesMembers { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractFoundationMembers is the foundation members contracts references. + ContractFoundationMembers = func() (result [GenesisAmountFoundationMembers]insolar.Reference) { + for i, name := range GenesisNameFoundationMembers { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractEnterpriseMembers is the enterprise members contracts references. + ContractEnterpriseMembers = func() (result [GenesisAmountEnterpriseMembers]insolar.Reference) { + for i, name := range GenesisNameEnterpriseMembers { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractNetworkIncentivesWallets is the network incentives members contracts references. + ContractNetworkIncentivesWallets = func() (result [GenesisAmountNetworkIncentivesMembers]insolar.Reference) { + for i, name := range GenesisNameNetworkIncentivesWallets { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractApplicationIncentivesWallets is the application incentives members contracts references. + ContractApplicationIncentivesWallets = func() (result [GenesisAmountApplicationIncentivesMembers]insolar.Reference) { + for i, name := range GenesisNameApplicationIncentivesWallets { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractFoundationWallets is the foundation members contracts references. + ContractFoundationWallets = func() (result [GenesisAmountFoundationMembers]insolar.Reference) { + for i, name := range GenesisNameFoundationWallets { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractEnterpriseWallets is the enterprise members contracts references. + ContractEnterpriseWallets = func() (result [GenesisAmountEnterpriseMembers]insolar.Reference) { + for i, name := range GenesisNameEnterpriseWallets { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractNetworkIncentivesDeposits is the network incentives deposits contracts references. + ContractNetworkIncentivesDeposits = func() (result [GenesisAmountNetworkIncentivesMembers]insolar.Reference) { + for i, name := range GenesisNameNetworkIncentivesDeposits { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractApplicationIncentivesDeposits is the application incentives deposits contracts references. + ContractApplicationIncentivesDeposits = func() (result [GenesisAmountApplicationIncentivesMembers]insolar.Reference) { + for i, name := range GenesisNameApplicationIncentivesDeposits { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractFoundationDeposits is the foundation deposits contracts references. + ContractFoundationDeposits = func() (result [GenesisAmountFoundationMembers]insolar.Reference) { + for i, name := range GenesisNameFoundationDeposits { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractNetworkIncentivesAccounts is the network incentives accounts contracts references. + ContractNetworkIncentivesAccounts = func() (result [GenesisAmountNetworkIncentivesMembers]insolar.Reference) { + for i, name := range GenesisNameNetworkIncentivesAccounts { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractApplicationIncentivesAccounts is the application incentives accounts contracts references. + ContractApplicationIncentivesAccounts = func() (result [GenesisAmountApplicationIncentivesMembers]insolar.Reference) { + for i, name := range GenesisNameApplicationIncentivesAccounts { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractFoundationAccounts is the foundation accounts contracts references. + ContractFoundationAccounts = func() (result [GenesisAmountFoundationMembers]insolar.Reference) { + for i, name := range GenesisNameFoundationAccounts { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() + + // ContractEnterpriseAccounts is the enterprise accounts contracts references. + ContractEnterpriseAccounts = func() (result [GenesisAmountFoundationMembers]insolar.Reference) { + for i, name := range GenesisNameEnterpriseAccounts { + result[i] = genesisrefs.GenesisRef(name) + } + return + }() +) + +// Get reference RootMember contract. +func GetRootMember() insolar.Reference { + return ContractRootMember +} + +// Get reference on RootDomain contract. +func GetRootDomain() insolar.Reference { + return ContractRootDomain +} + +// ContractPublicKeyNameShards is the public key shards contracts names. +func ContractPublicKeyNameShards(pkShardCount int) []string { + result := make([]string, pkShardCount) + for i := 0; i < pkShardCount; i++ { + name := GenesisNamePKShard + strconv.Itoa(i) + result[i] = name + } + return result +} + +// ContractPublicKeyShards is the public key shards contracts references. +func ContractPublicKeyShards(pkShardCount int) []insolar.Reference { + result := make([]insolar.Reference, pkShardCount) + for i, name := range ContractPublicKeyNameShards(pkShardCount) { + result[i] = genesisrefs.GenesisRef(name) + } + return result +} + +// ContractMigrationAddressNameShards is the migration address shards contracts names. +func ContractMigrationAddressNameShards(maShardCount int) []string { + result := make([]string, maShardCount) + for i := 0; i < maShardCount; i++ { + name := GenesisNameMigrationShard + strconv.Itoa(i) + result[i] = name + } + return result +} + +// ContractMigrationAddressShards is the migration address shards contracts references. +func ContractMigrationAddressShards(maShardCount int) []insolar.Reference { + result := make([]insolar.Reference, maShardCount) + for i, name := range ContractMigrationAddressNameShards(maShardCount) { + result[i] = genesisrefs.GenesisRef(name) + } + return result +} + +func ContractPublicKeyShardRefs(pkShardCount int) { + for _, name := range ContractPublicKeyNameShards(pkShardCount) { + genesisrefs.PredefinedPrototypes[name+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(preprocessor.PrototypeType, GenesisNamePKShard, 0) + } +} + +func ContractMigrationAddressShardRefs(maShardCount int) { + for _, name := range ContractMigrationAddressNameShards(maShardCount) { + genesisrefs.PredefinedPrototypes[name+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(preprocessor.PrototypeType, GenesisNameMigrationShard, 0) + } +} diff --git a/application/genesisrefs/refs_test.go b/application/genesis/refs_test.go similarity index 73% rename from application/genesisrefs/refs_test.go rename to application/genesis/refs_test.go index 0b5a655..90afcd0 100644 --- a/application/genesisrefs/refs_test.go +++ b/application/genesis/refs_test.go @@ -3,7 +3,7 @@ // This material is licensed under the Insolar License version 1.0, // available at https://github.com/insolar/mainnet/blob/master/LICENSE.md. -package genesisrefs +package genesis import ( "strconv" @@ -13,18 +13,17 @@ import ( "github.com/insolar/insolar/applicationbase/genesisrefs" "github.com/insolar/insolar/insolar" - "github.com/insolar/mainnet/application" ) func TestContractPublicKeyShards(t *testing.T) { for i, ref := range ContractPublicKeyShards(100) { - require.Equal(t, genesisrefs.GenesisRef(application.GenesisNamePKShard+strconv.Itoa(i)), ref) + require.Equal(t, genesisrefs.GenesisRef(GenesisNamePKShard+strconv.Itoa(i)), ref) } } func TestContractMigrationAddressShards(t *testing.T) { for i, ref := range ContractMigrationAddressShards(100) { - require.Equal(t, genesisrefs.GenesisRef(application.GenesisNameMigrationShard+strconv.Itoa(i)), ref) + require.Equal(t, genesisrefs.GenesisRef(GenesisNameMigrationShard+strconv.Itoa(i)), ref) } } @@ -33,47 +32,47 @@ func TestReferences(t *testing.T) { got insolar.Reference expect string }{ - application.GenesisNameRootDomain: { + GenesisNameRootDomain: { got: ContractRootDomain, expect: "insolar:1AAEAAciWtcmPVgAcaIvICkgnSsJmp4Clp650xOHjYks", }, - application.GenesisNameRootMember: { + GenesisNameRootMember: { got: ContractRootMember, expect: "insolar:1AAEAAWeNhA_NwKaH6E36IJ-2PLvXnJRxiTTNWq1giOg", }, - application.GenesisNameRootWallet: { + GenesisNameRootWallet: { got: ContractRootWallet, expect: "insolar:1AAEAAVEt_2mipoVG73cbK-v33ne0krJWXkZibayYKJc", }, - application.GenesisNameRootAccount: { + GenesisNameRootAccount: { got: ContractRootAccount, expect: "insolar:1AAEAAYUzPb6A9YCwdhstSMjq8g4dV_059cFrscpHemo", }, - application.GenesisNameDeposit: { + GenesisNameDeposit: { got: ContractDeposit, expect: "insolar:1AAEAAVnfpSe6gLpJptcggYUNNGIu0-_kxjnef5G-nR0", }, - application.GenesisNameCostCenter: { + GenesisNameCostCenter: { got: ContractCostCenter, expect: "insolar:1AAEAASCuYBHyztkBdO3b5lDXgDsrk12PKOTixEW6kvY", }, - application.GenesisNameFeeAccount: { + GenesisNameFeeAccount: { got: ContractFeeAccount, expect: "insolar:1AAEAAaN2AfiHUl4HxtCcMV-KhWirOx2MA69ndZVAIpM", }, - application.GenesisNameFeeWallet: { + GenesisNameFeeWallet: { got: ContractFeeWallet, expect: "insolar:1AAEAAVsLfNjPCXS5hsvt1WHuo0RZIYCs1H3oFC2jxIM", }, - application.GenesisNamePKShard: { + GenesisNamePKShard: { got: ContractPublicKeyShards(10)[0], expect: "insolar:1AAEAAVM1LnFXwPa92gplaRhMroFeWi-gxznLptCtPCc", }, - application.GenesisNameMigrationShard: { + GenesisNameMigrationShard: { got: ContractMigrationAddressShards(10)[0], expect: "insolar:1AAEAAVvqEYcaRInGWx75iJWNLUSuWXU5XA3L8Qh0fpU", }, - application.GenesisNameMigrationAdminAccount: { + GenesisNameMigrationAdminAccount: { got: ContractMigrationAccount, expect: "insolar:1AAEAAYHatrmIZwsoJ3Fy78F9Q1zZ9bEuxRrZasAcYYo", }, @@ -88,6 +87,6 @@ func TestReferences(t *testing.T) { func TestRootDomain(t *testing.T) { ref1 := ContractRootDomain - ref2 := genesisrefs.GenesisRef(application.GenesisNameRootDomain) + ref2 := genesisrefs.GenesisRef(GenesisNameRootDomain) require.Equal(t, ref1.String(), ref2.String(), "reference is the same") } diff --git a/application/genesisrefs/contracts/contracts.go b/application/genesisrefs/contracts/contracts.go deleted file mode 100644 index 8109fdb..0000000 --- a/application/genesisrefs/contracts/contracts.go +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright 2020 Insolar Network Ltd. -// All rights reserved. -// This material is licensed under the Insolar License version 1.0, -// available at https://github.com/insolar/mainnet/blob/master/LICENSE.md. - -package contracts - -import ( - "fmt" - - "github.com/insolar/insolar/applicationbase/genesis" - "github.com/insolar/mainnet/application" - "github.com/insolar/mainnet/application/genesisrefs" - - "github.com/insolar/mainnet/application/builtin/contract/account" - "github.com/insolar/mainnet/application/builtin/contract/costcenter" - "github.com/insolar/mainnet/application/builtin/contract/deposit" - "github.com/insolar/mainnet/application/builtin/contract/member" - "github.com/insolar/mainnet/application/builtin/contract/migrationadmin" - "github.com/insolar/mainnet/application/builtin/contract/migrationdaemon" - "github.com/insolar/mainnet/application/builtin/contract/migrationshard" - "github.com/insolar/mainnet/application/builtin/contract/pkshard" - "github.com/insolar/mainnet/application/builtin/contract/rootdomain" - "github.com/insolar/mainnet/application/builtin/contract/wallet" - - "github.com/insolar/insolar/insolar" - "github.com/insolar/insolar/logicrunner/builtin/foundation" - "github.com/insolar/insolar/pulse" - "github.com/insolar/mainnet/application/appfoundation" -) - -func RootDomain(pkShardCount int) genesis.ContractState { - - return genesis.ContractState{ - Name: application.GenesisNameRootDomain, - Prototype: application.GenesisNameRootDomain, - ParentName: "", - - Memory: genesis.MustGenMemory(&rootdomain.RootDomain{ - PublicKeyShards: genesisrefs.ContractPublicKeyShards(pkShardCount), - }), - } -} - -func GetMemberGenesisContractState(publicKey string, name string, parent string, walletRef insolar.Reference) genesis.ContractState { - m, err := member.New(publicKey, "", *insolar.NewEmptyReference()) - if err != nil { - panic(fmt.Sprintf("'%s' member constructor failed", name)) - } - - m.Wallet = walletRef - - return genesis.ContractState{ - Name: name, - Prototype: application.GenesisNameMember, - ParentName: parent, - Memory: genesis.MustGenMemory(m), - } -} - -func GetWalletGenesisContractState(name string, parent string, accountRef insolar.Reference) genesis.ContractState { - w, err := wallet.New(accountRef) - if err != nil { - panic("failed to create ` " + name + "` wallet instance") - } - - return genesis.ContractState{ - Name: name, - Prototype: application.GenesisNameWallet, - ParentName: parent, - Memory: genesis.MustGenMemory(w), - } -} - -func GetPreWalletGenesisContractState(name string, parent string, accounts foundation.StableMap, deposits foundation.StableMap) genesis.ContractState { - return genesis.ContractState{ - Name: name, - Prototype: application.GenesisNameWallet, - ParentName: parent, - Memory: genesis.MustGenMemory(&wallet.Wallet{ - Accounts: accounts, - Deposits: deposits, - }), - } -} - -func GetAccountGenesisContractState(balance string, name string, parent string) genesis.ContractState { - w, err := account.New(balance) - if err != nil { - panic("failed to create ` " + name + "` account instance") - } - - return genesis.ContractState{ - Name: name, - Prototype: application.GenesisNameAccount, - ParentName: parent, - Memory: genesis.MustGenMemory(w), - } -} - -func GetCostCenterGenesisContractState() genesis.ContractState { - cc, err := costcenter.New(&genesisrefs.ContractFeeMember) - if err != nil { - panic("failed to create cost center instance") - } - - return genesis.ContractState{ - Name: application.GenesisNameCostCenter, - Prototype: application.GenesisNameCostCenter, - ParentName: application.GenesisNameRootDomain, - Memory: genesis.MustGenMemory(cc), - } -} - -func GetPKShardGenesisContractState(name string, members foundation.StableMap) genesis.ContractState { - s, err := pkshard.New(members) - if err != nil { - panic(fmt.Sprintf("'%s' shard constructor failed", name)) - } - - return genesis.ContractState{ - Name: name, - Prototype: application.GenesisNamePKShard, - ParentName: application.GenesisNameRootDomain, - Memory: genesis.MustGenMemory(s), - } -} - -func GetMigrationShardGenesisContractState(name string, migrationAddresses []string) genesis.ContractState { - s, err := migrationshard.New(migrationAddresses) - if err != nil { - panic(fmt.Sprintf("'%s' shard constructor failed", name)) - } - - return genesis.ContractState{ - Name: name, - Prototype: application.GenesisNameMigrationShard, - ParentName: application.GenesisNameRootDomain, - Memory: genesis.MustGenMemory(s), - } -} - -func GetMigrationAdminGenesisContractState(lockup int64, vesting int64, vestingStep int64, maShardCount int) genesis.ContractState { - return genesis.ContractState{ - Name: application.GenesisNameMigrationAdmin, - Prototype: application.GenesisNameMigrationAdmin, - ParentName: application.GenesisNameRootDomain, - Memory: genesis.MustGenMemory(&migrationadmin.MigrationAdmin{ - MigrationAddressShards: genesisrefs.ContractMigrationAddressShards(maShardCount), - MigrationAdminMember: genesisrefs.ContractMigrationAdminMember, - VestingParams: &migrationadmin.VestingParams{ - Lockup: lockup, - Vesting: vesting, - VestingStep: vestingStep, - }, - }), - } -} - -func GetDepositGenesisContractState( - amount string, - vesting int64, - vestingStep int64, - vestingType appfoundation.VestingType, - pulseDepositUnHold insolar.PulseNumber, - name string, parent string, -) genesis.ContractState { - return genesis.ContractState{ - Name: name, - Prototype: application.GenesisNameDeposit, - ParentName: parent, - Memory: genesis.MustGenMemory(&deposit.Deposit{ - Balance: amount, - Amount: amount, - PulseDepositUnHold: pulseDepositUnHold, - VestingType: vestingType, - TxHash: genesisrefs.FundsDepositName, - Lockup: int64(pulseDepositUnHold - pulse.MinTimePulse), - Vesting: vesting, - VestingStep: vestingStep, - IsConfirmed: true, - }), - } -} - -func GetMigrationDaemonGenesisContractState(numberMigrationDaemon int) genesis.ContractState { - - return genesis.ContractState{ - Name: application.GenesisNameMigrationDaemons[numberMigrationDaemon], - Prototype: application.GenesisNameMigrationDaemon, - ParentName: application.GenesisNameRootDomain, - Memory: genesis.MustGenMemory(&migrationdaemon.MigrationDaemon{ - IsActive: false, - MigrationDaemonMember: genesisrefs.ContractMigrationDaemonMembers[numberMigrationDaemon], - }), - } -} diff --git a/application/genesisrefs/refs.go b/application/genesisrefs/refs.go deleted file mode 100644 index 449fabb..0000000 --- a/application/genesisrefs/refs.go +++ /dev/null @@ -1,323 +0,0 @@ -// Copyright 2020 Insolar Network Ltd. -// All rights reserved. -// This material is licensed under the Insolar License version 1.0, -// available at https://github.com/insolar/mainnet/blob/master/LICENSE.md. - -package genesisrefs - -import ( - "strconv" - - "github.com/insolar/insolar/applicationbase/genesisrefs" - "github.com/insolar/insolar/insolar" - "github.com/insolar/insolar/logicrunner/preprocessor" - "github.com/insolar/mainnet/application" -) - -const ( - FundsDepositName = "genesis_deposit" -) - -var applicationPrototypes = map[string]insolar.Reference{ - application.GenesisNameRootDomain + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameRootDomain, 0), - application.GenesisNameRootMember + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMember, 0), - application.GenesisNameRootWallet + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameWallet, 0), - application.GenesisNameRootAccount + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameAccount, 0), - application.GenesisNameCostCenter + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameCostCenter, 0), - application.GenesisNameFeeMember + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMember, 0), - application.GenesisNameFeeWallet + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameWallet, 0), - application.GenesisNameFeeAccount + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameAccount, 0), - application.GenesisNameDeposit + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameDeposit, 0), - application.GenesisNameMember + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMember, 0), - application.GenesisNameMigrationAdminMember + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMember, 0), - application.GenesisNameMigrationAdmin + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMigrationAdmin, 0), - application.GenesisNameMigrationAdminWallet + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameWallet, 0), - application.GenesisNameMigrationAdminAccount + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameAccount, 0), - application.GenesisNameMigrationAdminDeposit + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameDeposit, 0), - application.GenesisNameWallet + genesisrefs.PrototypeSuffix: *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameWallet, 0), -} - -func init() { - for i, val := range applicationPrototypes { - genesisrefs.PredefinedPrototypes[i] = val - } - - for _, el := range application.GenesisNameMigrationDaemonMembers { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMember, 0) - } - - for _, el := range application.GenesisNameMigrationDaemons { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMigrationDaemon, 0) - } - - // Incentives Application - for _, el := range application.GenesisNameApplicationIncentivesMembers { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMember, 0) - } - for _, el := range application.GenesisNameApplicationIncentivesWallets { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameWallet, 0) - } - for _, el := range application.GenesisNameApplicationIncentivesAccounts { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameAccount, 0) - } - for _, el := range application.GenesisNameApplicationIncentivesDeposits { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameDeposit, 0) - } - - // Network Incentives - for _, el := range application.GenesisNameNetworkIncentivesMembers { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMember, 0) - } - for _, el := range application.GenesisNameNetworkIncentivesWallets { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameWallet, 0) - } - for _, el := range application.GenesisNameNetworkIncentivesAccounts { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameAccount, 0) - } - for _, el := range application.GenesisNameNetworkIncentivesDeposits { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameDeposit, 0) - } - - // Foundation - for _, el := range application.GenesisNameFoundationMembers { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMember, 0) - } - for _, el := range application.GenesisNameFoundationWallets { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameWallet, 0) - } - for _, el := range application.GenesisNameFoundationAccounts { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameAccount, 0) - } - for _, el := range application.GenesisNameFoundationDeposits { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameDeposit, 0) - } - - // Enterprise - for _, el := range application.GenesisNameEnterpriseMembers { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameMember, 0) - } - for _, el := range application.GenesisNameEnterpriseWallets { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameWallet, 0) - } - for _, el := range application.GenesisNameEnterpriseAccounts { - genesisrefs.PredefinedPrototypes[el+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(genesisrefs.PrototypeType, application.GenesisNameAccount, 0) - } -} - -var ( - // ContractRootDomain is the root domain contract reference. - ContractRootDomain = genesisrefs.GenesisRef(application.GenesisNameRootDomain) - // ContractRootMember is the root member contract reference. - ContractRootMember = genesisrefs.GenesisRef(application.GenesisNameRootMember) - // ContractRootWallet is the root wallet contract reference. - ContractRootWallet = genesisrefs.GenesisRef(application.GenesisNameRootWallet) - // ContractRootAccount is the root account contract reference. - ContractRootAccount = genesisrefs.GenesisRef(application.GenesisNameRootAccount) - // ContractMigrationAdminMember is the migration admin member contract reference. - ContractMigrationAdminMember = genesisrefs.GenesisRef(application.GenesisNameMigrationAdminMember) - // ContractMigrationAdmin is the migration wallet contract reference. - ContractMigrationAdmin = genesisrefs.GenesisRef(application.GenesisNameMigrationAdmin) - // ContractMigrationWallet is the migration wallet contract reference. - ContractMigrationWallet = genesisrefs.GenesisRef(application.GenesisNameMigrationAdminWallet) - // ContractMigrationAccount is the migration account contract reference. - ContractMigrationAccount = genesisrefs.GenesisRef(application.GenesisNameMigrationAdminAccount) - // ContractMigrationDeposit is the migration deposit contract reference. - ContractMigrationDeposit = genesisrefs.GenesisRef(application.GenesisNameMigrationAdminDeposit) - // ContractDeposit is the deposit contract reference. - ContractDeposit = genesisrefs.GenesisRef(application.GenesisNameDeposit) - // ContractCostCenter is the cost center contract reference. - ContractCostCenter = genesisrefs.GenesisRef(application.GenesisNameCostCenter) - // ContractFeeMember is the fee member contract reference. - ContractFeeMember = genesisrefs.GenesisRef(application.GenesisNameFeeMember) - // ContractFeeWallet is the fee wallet contract reference. - ContractFeeWallet = genesisrefs.GenesisRef(application.GenesisNameFeeWallet) - // ContractFeeAccount is the fee account contract reference. - ContractFeeAccount = genesisrefs.GenesisRef(application.GenesisNameFeeAccount) - - // ContractMigrationDaemonMembers is the migration daemon members contracts references. - ContractMigrationDaemonMembers = func() (result [application.GenesisAmountMigrationDaemonMembers]insolar.Reference) { - for i, name := range application.GenesisNameMigrationDaemonMembers { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractMigrationMap where key is migration daemon member references and value related migration daemon contract - ContractMigrationMap = func() (result map[insolar.Reference]insolar.Reference) { - result = make(map[insolar.Reference]insolar.Reference) - for i := 0; i < application.GenesisAmountMigrationDaemonMembers; i++ { - result[genesisrefs.GenesisRef(application.GenesisNameMigrationDaemonMembers[i])] = genesisrefs.GenesisRef(application.GenesisNameMigrationDaemons[i]) - } - return - }() - - // ContractNetworkIncentivesMembers is the network incentives members contracts references. - ContractNetworkIncentivesMembers = func() (result [application.GenesisAmountNetworkIncentivesMembers]insolar.Reference) { - for i, name := range application.GenesisNameNetworkIncentivesMembers { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractApplicationIncentivesMembers is the application incentives members contracts references. - ContractApplicationIncentivesMembers = func() (result [application.GenesisAmountApplicationIncentivesMembers]insolar.Reference) { - for i, name := range application.GenesisNameApplicationIncentivesMembers { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractFoundationMembers is the foundation members contracts references. - ContractFoundationMembers = func() (result [application.GenesisAmountFoundationMembers]insolar.Reference) { - for i, name := range application.GenesisNameFoundationMembers { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractEnterpriseMembers is the enterprise members contracts references. - ContractEnterpriseMembers = func() (result [application.GenesisAmountEnterpriseMembers]insolar.Reference) { - for i, name := range application.GenesisNameEnterpriseMembers { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractNetworkIncentivesWallets is the network incentives members contracts references. - ContractNetworkIncentivesWallets = func() (result [application.GenesisAmountNetworkIncentivesMembers]insolar.Reference) { - for i, name := range application.GenesisNameNetworkIncentivesWallets { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractApplicationIncentivesWallets is the application incentives members contracts references. - ContractApplicationIncentivesWallets = func() (result [application.GenesisAmountApplicationIncentivesMembers]insolar.Reference) { - for i, name := range application.GenesisNameApplicationIncentivesWallets { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractFoundationWallets is the foundation members contracts references. - ContractFoundationWallets = func() (result [application.GenesisAmountFoundationMembers]insolar.Reference) { - for i, name := range application.GenesisNameFoundationWallets { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractEnterpriseWallets is the enterprise members contracts references. - ContractEnterpriseWallets = func() (result [application.GenesisAmountEnterpriseMembers]insolar.Reference) { - for i, name := range application.GenesisNameEnterpriseWallets { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractNetworkIncentivesDeposits is the network incentives deposits contracts references. - ContractNetworkIncentivesDeposits = func() (result [application.GenesisAmountNetworkIncentivesMembers]insolar.Reference) { - for i, name := range application.GenesisNameNetworkIncentivesDeposits { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractApplicationIncentivesDeposits is the application incentives deposits contracts references. - ContractApplicationIncentivesDeposits = func() (result [application.GenesisAmountApplicationIncentivesMembers]insolar.Reference) { - for i, name := range application.GenesisNameApplicationIncentivesDeposits { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractFoundationDeposits is the foundation deposits contracts references. - ContractFoundationDeposits = func() (result [application.GenesisAmountFoundationMembers]insolar.Reference) { - for i, name := range application.GenesisNameFoundationDeposits { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractNetworkIncentivesAccounts is the network incentives accounts contracts references. - ContractNetworkIncentivesAccounts = func() (result [application.GenesisAmountNetworkIncentivesMembers]insolar.Reference) { - for i, name := range application.GenesisNameNetworkIncentivesAccounts { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractApplicationIncentivesAccounts is the application incentives accounts contracts references. - ContractApplicationIncentivesAccounts = func() (result [application.GenesisAmountApplicationIncentivesMembers]insolar.Reference) { - for i, name := range application.GenesisNameApplicationIncentivesAccounts { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractFoundationAccounts is the foundation accounts contracts references. - ContractFoundationAccounts = func() (result [application.GenesisAmountFoundationMembers]insolar.Reference) { - for i, name := range application.GenesisNameFoundationAccounts { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() - - // ContractEnterpriseAccounts is the enterprise accounts contracts references. - ContractEnterpriseAccounts = func() (result [application.GenesisAmountFoundationMembers]insolar.Reference) { - for i, name := range application.GenesisNameEnterpriseAccounts { - result[i] = genesisrefs.GenesisRef(name) - } - return - }() -) - -// ContractPublicKeyNameShards is the public key shards contracts names. -func ContractPublicKeyNameShards(pkShardCount int) []string { - result := make([]string, pkShardCount) - for i := 0; i < pkShardCount; i++ { - name := application.GenesisNamePKShard + strconv.Itoa(i) - result[i] = name - } - return result -} - -// ContractPublicKeyShards is the public key shards contracts references. -func ContractPublicKeyShards(pkShardCount int) []insolar.Reference { - result := make([]insolar.Reference, pkShardCount) - for i, name := range ContractPublicKeyNameShards(pkShardCount) { - result[i] = genesisrefs.GenesisRef(name) - } - return result -} - -// ContractMigrationAddressNameShards is the migration address shards contracts names. -func ContractMigrationAddressNameShards(maShardCount int) []string { - result := make([]string, maShardCount) - for i := 0; i < maShardCount; i++ { - name := application.GenesisNameMigrationShard + strconv.Itoa(i) - result[i] = name - } - return result -} - -// ContractMigrationAddressShards is the migration address shards contracts references. -func ContractMigrationAddressShards(maShardCount int) []insolar.Reference { - result := make([]insolar.Reference, maShardCount) - for i, name := range ContractMigrationAddressNameShards(maShardCount) { - result[i] = genesisrefs.GenesisRef(name) - } - return result -} - -func ContractPublicKeyShardRefs(pkShardCount int) { - for _, name := range ContractPublicKeyNameShards(pkShardCount) { - genesisrefs.PredefinedPrototypes[name+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(preprocessor.PrototypeType, application.GenesisNamePKShard, 0) - } -} - -func ContractMigrationAddressShardRefs(maShardCount int) { - for _, name := range ContractMigrationAddressNameShards(maShardCount) { - genesisrefs.PredefinedPrototypes[name+genesisrefs.PrototypeSuffix] = *genesisrefs.GenerateProtoReferenceFromContractID(preprocessor.PrototypeType, application.GenesisNameMigrationShard, 0) - } -} diff --git a/application/sdk/sdk.go b/application/sdk/sdk.go index 7f94a14..1433042 100644 --- a/application/sdk/sdk.go +++ b/application/sdk/sdk.go @@ -24,8 +24,8 @@ import ( "github.com/insolar/insolar/api/requester" "github.com/insolar/insolar/insolar" "github.com/insolar/insolar/instrumentation/inslogger" - "github.com/insolar/mainnet/application" - "github.com/insolar/mainnet/application/bootstrap" + "github.com/insolar/mainnet/application/genesis" + "github.com/insolar/mainnet/application/genesis/contracts" ) type ringBuffer struct { @@ -124,13 +124,13 @@ func NewSDK(adminUrls []string, publicUrls []string, memberKeysDirPath string, o options: options, } - if len(response.MigrationDaemonMembers) < application.GenesisAmountMigrationDaemonMembers { - return nil, errors.New(fmt.Sprintf("need at least '%d' migration daemons", application.GenesisAmountActiveMigrationDaemonMembers)) + if len(response.MigrationDaemonMembers) < genesis.GenesisAmountMigrationDaemonMembers { + return nil, errors.New(fmt.Sprintf("need at least '%d' migration daemons", genesis.GenesisAmountActiveMigrationDaemonMembers)) } - for i := 0; i < application.GenesisAmountMigrationDaemonMembers; i++ { + for i := 0; i < genesis.GenesisAmountMigrationDaemonMembers; i++ { m, err := getMember( - filepath.Join(memberKeysDirPath, bootstrap.GetMigrationDaemonPath(i)), response.MigrationDaemonMembers[i]) + filepath.Join(memberKeysDirPath, contracts.GetMigrationDaemonPath(i)), response.MigrationDaemonMembers[i]) if err != nil { return nil, errors.Wrap(err, fmt.Sprintf("failed to get migration daemon member; member's index: '%d'", i)) } diff --git a/cmd/insolard/genesisstate/genesis.go b/cmd/insolard/genesisstate/genesis.go deleted file mode 100644 index 9df7e18..0000000 --- a/cmd/insolard/genesisstate/genesis.go +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright 2020 Insolar Network Ltd. -// All rights reserved. -// This material is licensed under the Insolar License version 1.0, -// available at https://github.com/insolar/mainnet/blob/master/LICENSE.md. - -package genesisstate - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "time" - - "github.com/pkg/errors" - - "github.com/insolar/insolar/applicationbase/genesis" - "github.com/insolar/insolar/insolar" - "github.com/insolar/insolar/log" - "github.com/insolar/insolar/logicrunner/builtin/foundation" - "github.com/insolar/insolar/pulse" - - "github.com/insolar/mainnet/application" - "github.com/insolar/mainnet/application/appfoundation" - "github.com/insolar/mainnet/application/genesisrefs" - "github.com/insolar/mainnet/application/genesisrefs/contracts" -) - -const ( - XNS = "XNS" - MigrationDaemonUnholdDate = 1596456000 // 03.08.2020 12-00-00 - MigrationDaemonVesting = 0 - MigrationDaemonVestingStep = 0 - - NetworkIncentivesUnholdStartDate = 1583020800 // 01.03.2020 00-00-00 - NetworkIncentivesVesting = 0 - NetworkIncentivesVestingStep = 0 - - ApplicationIncentivesUnholdStartDate = 1609459200 // 01.01.2021 00-00-00 - ApplicationIncentivesVesting = 0 - ApplicationIncentivesVestingStep = 0 - - FoundationUnholdStartDate = 1609459200 // 01.01.2021 00-00-00 - FoundationVestingPeriod = 0 - FoundationVestingStep = 0 -) - -func InitStates(genesisConfigPath string) ([]genesis.ContractState, error) { - b, err := ioutil.ReadFile(genesisConfigPath) - if err != nil { - log.Fatalf("failed to load genesis configuration from file: %v", genesisConfigPath) - } - var config struct { - ContractsConfig application.GenesisContractsConfig - } - err = json.Unmarshal(b, &config) - if err != nil { - log.Fatalf("failed to parse genesis configuration from file: %v", genesisConfigPath) - } - - contractsConfig := config.ContractsConfig - - migrationAccounts := make(foundation.StableMap) - migrationAccounts[XNS] = genesisrefs.ContractMigrationAccount.String() - - migrationDeposits := make(foundation.StableMap) - migrationDeposits[genesisrefs.FundsDepositName] = genesisrefs.ContractMigrationDeposit.String() - - genesisrefs.ContractMigrationAddressShardRefs(contractsConfig.MAShardCount) - genesisrefs.ContractPublicKeyShardRefs(contractsConfig.PKShardCount) - - // Hint: order matters, because of dependency contracts on each other. - states := []genesis.ContractState{ - contracts.RootDomain(contractsConfig.PKShardCount), - contracts.GetMemberGenesisContractState(contractsConfig.RootPublicKey, application.GenesisNameRootMember, application.GenesisNameRootDomain, genesisrefs.ContractRootWallet), - contracts.GetMemberGenesisContractState(contractsConfig.MigrationAdminPublicKey, application.GenesisNameMigrationAdminMember, application.GenesisNameRootDomain, genesisrefs.ContractMigrationWallet), - contracts.GetMemberGenesisContractState(contractsConfig.FeePublicKey, application.GenesisNameFeeMember, application.GenesisNameRootDomain, genesisrefs.ContractFeeWallet), - - contracts.GetWalletGenesisContractState(application.GenesisNameRootWallet, application.GenesisNameRootDomain, genesisrefs.ContractRootAccount), - contracts.GetPreWalletGenesisContractState(application.GenesisNameMigrationAdminWallet, application.GenesisNameRootDomain, migrationAccounts, migrationDeposits), - contracts.GetWalletGenesisContractState(application.GenesisNameFeeWallet, application.GenesisNameRootDomain, genesisrefs.ContractFeeAccount), - - contracts.GetAccountGenesisContractState(contractsConfig.RootBalance, application.GenesisNameRootAccount, application.GenesisNameRootDomain), - contracts.GetAccountGenesisContractState("0", application.GenesisNameMigrationAdminAccount, application.GenesisNameRootDomain), - contracts.GetAccountGenesisContractState("0", application.GenesisNameFeeAccount, application.GenesisNameRootDomain), - - contracts.GetDepositGenesisContractState( - contractsConfig.MDBalance, - MigrationDaemonVesting, - MigrationDaemonVestingStep, - appfoundation.Vesting2, - pulse.OfUnixTime(MigrationDaemonUnholdDate), // Unhold date - application.GenesisNameMigrationAdminDeposit, - application.GenesisNameRootDomain, - ), - contracts.GetMigrationAdminGenesisContractState(contractsConfig.LockupPeriodInPulses, contractsConfig.VestingPeriodInPulses, contractsConfig.VestingStepInPulses, contractsConfig.MAShardCount), - contracts.GetCostCenterGenesisContractState(), - } - - for i, key := range contractsConfig.MigrationDaemonPublicKeys { - states = append(states, contracts.GetMemberGenesisContractState(key, application.GenesisNameMigrationDaemonMembers[i], application.GenesisNameRootDomain, *insolar.NewEmptyReference())) - states = append(states, contracts.GetMigrationDaemonGenesisContractState(i)) - } - - for i, key := range contractsConfig.ApplicationIncentivesPublicKeys { - states = append(states, contracts.GetMemberGenesisContractState(key, application.GenesisNameApplicationIncentivesMembers[i], application.GenesisNameRootDomain, genesisrefs.ContractApplicationIncentivesWallets[i])) - - states = append(states, contracts.GetAccountGenesisContractState("0", application.GenesisNameApplicationIncentivesAccounts[i], application.GenesisNameRootDomain)) - - unholdWithMonth := time.Unix(ApplicationIncentivesUnholdStartDate, 0).AddDate(0, i, 0).Unix() - - states = append(states, contracts.GetDepositGenesisContractState( - application.AppIncentivesDistributionAmount, - ApplicationIncentivesVesting, - ApplicationIncentivesVestingStep, - appfoundation.Vesting2, - pulse.OfUnixTime(unholdWithMonth), - application.GenesisNameApplicationIncentivesDeposits[i], - application.GenesisNameRootDomain, - )) - - membersAccounts := make(foundation.StableMap) - membersAccounts[XNS] = genesisrefs.ContractApplicationIncentivesAccounts[i].String() - - membersDeposits := make(foundation.StableMap) - membersDeposits[genesisrefs.FundsDepositName] = genesisrefs.ContractApplicationIncentivesDeposits[i].String() - - states = append(states, contracts.GetPreWalletGenesisContractState( - application.GenesisNameApplicationIncentivesWallets[i], - application.GenesisNameRootDomain, - membersAccounts, - membersDeposits, - )) - } - - for i, key := range contractsConfig.NetworkIncentivesPublicKeys { - states = append(states, contracts.GetMemberGenesisContractState(key, application.GenesisNameNetworkIncentivesMembers[i], application.GenesisNameRootDomain, genesisrefs.ContractNetworkIncentivesWallets[i])) - states = append(states, contracts.GetAccountGenesisContractState("0", application.GenesisNameNetworkIncentivesAccounts[i], application.GenesisNameRootDomain)) - - unholdWithMonth := time.Unix(NetworkIncentivesUnholdStartDate, 0).AddDate(0, i, 0).Unix() - - states = append(states, contracts.GetDepositGenesisContractState( - application.NetworkIncentivesDistributionAmount, - NetworkIncentivesVesting, - NetworkIncentivesVestingStep, - appfoundation.Vesting2, - pulse.OfUnixTime(unholdWithMonth), - application.GenesisNameNetworkIncentivesDeposits[i], - application.GenesisNameRootDomain, - )) - - membersAccounts := make(foundation.StableMap) - membersAccounts[XNS] = genesisrefs.ContractNetworkIncentivesAccounts[i].String() - - membersDeposits := make(foundation.StableMap) - membersDeposits[genesisrefs.FundsDepositName] = genesisrefs.ContractNetworkIncentivesDeposits[i].String() - - states = append(states, contracts.GetPreWalletGenesisContractState( - application.GenesisNameNetworkIncentivesWallets[i], - application.GenesisNameRootDomain, - membersAccounts, - membersDeposits, - )) - } - - for i, key := range contractsConfig.FoundationPublicKeys { - states = append(states, contracts.GetMemberGenesisContractState(key, application.GenesisNameFoundationMembers[i], application.GenesisNameRootDomain, genesisrefs.ContractFoundationWallets[i])) - states = append(states, contracts.GetAccountGenesisContractState("0", application.GenesisNameFoundationAccounts[i], application.GenesisNameRootDomain)) - - unholdWithMonth := time.Unix(FoundationUnholdStartDate, 0).AddDate(0, i, 0).Unix() - - states = append(states, contracts.GetDepositGenesisContractState( - application.FoundationDistributionAmount, - FoundationVestingPeriod, - FoundationVestingStep, - appfoundation.Vesting2, - pulse.OfUnixTime(unholdWithMonth), - application.GenesisNameFoundationDeposits[i], - application.GenesisNameRootDomain, - )) - - membersAccounts := make(foundation.StableMap) - membersAccounts[XNS] = genesisrefs.ContractFoundationAccounts[i].String() - - membersDeposits := make(foundation.StableMap) - membersDeposits[genesisrefs.FundsDepositName] = genesisrefs.ContractFoundationDeposits[i].String() - - states = append(states, contracts.GetPreWalletGenesisContractState( - application.GenesisNameFoundationWallets[i], - application.GenesisNameRootDomain, - membersAccounts, - membersDeposits, - )) - } - - for i, key := range contractsConfig.EnterprisePublicKeys { - states = append(states, contracts.GetMemberGenesisContractState(key, application.GenesisNameEnterpriseMembers[i], application.GenesisNameRootDomain, genesisrefs.ContractEnterpriseWallets[i])) - states = append(states, contracts.GetAccountGenesisContractState( - application.EnterpriseDistributionAmount, - application.GenesisNameEnterpriseAccounts[i], - application.GenesisNameRootDomain, - )) - - membersAccounts := make(foundation.StableMap) - membersAccounts[XNS] = genesisrefs.ContractEnterpriseAccounts[i].String() - - membersDeposits := make(foundation.StableMap) - - states = append(states, contracts.GetPreWalletGenesisContractState( - application.GenesisNameEnterpriseWallets[i], - application.GenesisNameRootDomain, - membersAccounts, - membersDeposits, - )) - } - - if contractsConfig.PKShardCount <= 0 { - panic(fmt.Sprintf("[genesis] store contracts failed: setup pk_shard_count parameter, current value %v", contractsConfig.PKShardCount)) - } - if contractsConfig.VestingStepInPulses > 0 && contractsConfig.VestingPeriodInPulses%contractsConfig.VestingStepInPulses != 0 { - panic(fmt.Sprintf("[genesis] store contracts failed: vesting_pulse_period (%d) is not a multiple of vesting_pulse_step (%d)", contractsConfig.VestingPeriodInPulses, contractsConfig.VestingStepInPulses)) - } - - // Split genesis members by PK shards - var membersByPKShards []foundation.StableMap - for i := 0; i < contractsConfig.PKShardCount; i++ { - membersByPKShards = append(membersByPKShards, make(foundation.StableMap)) - } - trimmedRootPublicKey, err := foundation.ExtractCanonicalPublicKey(contractsConfig.RootPublicKey) - if err != nil { - panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", contractsConfig.RootPublicKey)) - } - index := foundation.GetShardIndex(trimmedRootPublicKey, contractsConfig.PKShardCount) - membersByPKShards[index][trimmedRootPublicKey] = genesisrefs.ContractRootMember.String() - - trimmedMigrationAdminPublicKey, err := foundation.ExtractCanonicalPublicKey(contractsConfig.MigrationAdminPublicKey) - if err != nil { - panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", contractsConfig.MigrationAdminPublicKey)) - } - index = foundation.GetShardIndex(trimmedMigrationAdminPublicKey, contractsConfig.PKShardCount) - membersByPKShards[index][trimmedMigrationAdminPublicKey] = genesisrefs.ContractMigrationAdminMember.String() - - trimmedFeeMemberPublicKey, err := foundation.ExtractCanonicalPublicKey(contractsConfig.FeePublicKey) - if err != nil { - panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", contractsConfig.FeePublicKey)) - } - index = foundation.GetShardIndex(trimmedFeeMemberPublicKey, contractsConfig.PKShardCount) - membersByPKShards[index][trimmedFeeMemberPublicKey] = genesisrefs.ContractFeeMember.String() - - for i, key := range contractsConfig.MigrationDaemonPublicKeys { - trimmedMigrationDaemonPublicKey, err := foundation.ExtractCanonicalPublicKey(key) - if err != nil { - panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", key)) - } - index := foundation.GetShardIndex(trimmedMigrationDaemonPublicKey, contractsConfig.PKShardCount) - membersByPKShards[index][trimmedMigrationDaemonPublicKey] = genesisrefs.ContractMigrationDaemonMembers[i].String() - } - - for i, key := range contractsConfig.NetworkIncentivesPublicKeys { - trimmedNetworkIncentivesPublicKey, err := foundation.ExtractCanonicalPublicKey(key) - if err != nil { - panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", key)) - } - index := foundation.GetShardIndex(trimmedNetworkIncentivesPublicKey, contractsConfig.PKShardCount) - membersByPKShards[index][trimmedNetworkIncentivesPublicKey] = genesisrefs.ContractNetworkIncentivesMembers[i].String() - } - - for i, key := range contractsConfig.ApplicationIncentivesPublicKeys { - trimmedApplicationIncentivesPublicKey, err := foundation.ExtractCanonicalPublicKey(key) - if err != nil { - panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", key)) - } - index := foundation.GetShardIndex(trimmedApplicationIncentivesPublicKey, contractsConfig.PKShardCount) - membersByPKShards[index][trimmedApplicationIncentivesPublicKey] = genesisrefs.ContractApplicationIncentivesMembers[i].String() - } - - for i, key := range contractsConfig.FoundationPublicKeys { - trimmedFoundationPublicKey, err := foundation.ExtractCanonicalPublicKey(key) - if err != nil { - panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", key)) - } - index := foundation.GetShardIndex(trimmedFoundationPublicKey, contractsConfig.PKShardCount) - membersByPKShards[index][trimmedFoundationPublicKey] = genesisrefs.ContractFoundationMembers[i].String() - } - - for i, key := range contractsConfig.EnterprisePublicKeys { - trimmedEnterprisePublicKey, err := foundation.ExtractCanonicalPublicKey(key) - if err != nil { - panic(errors.Wrapf(err, "[genesis] extracting canonical pk failed, current value %v", key)) - } - index := foundation.GetShardIndex(trimmedEnterprisePublicKey, contractsConfig.PKShardCount) - membersByPKShards[index][trimmedEnterprisePublicKey] = genesisrefs.ContractEnterpriseMembers[i].String() - } - - // Append states for shards - for i, name := range genesisrefs.ContractPublicKeyNameShards(contractsConfig.PKShardCount) { - states = append(states, contracts.GetPKShardGenesisContractState(name, membersByPKShards[i])) - } - for i, name := range genesisrefs.ContractMigrationAddressNameShards(contractsConfig.MAShardCount) { - states = append(states, contracts.GetMigrationShardGenesisContractState(name, contractsConfig.MigrationAddresses[i])) - } - - return states, nil -} diff --git a/cmd/insolard/instrument_gops.go b/cmd/insolard/instrument_gops.go deleted file mode 100644 index ea8ca60..0000000 --- a/cmd/insolard/instrument_gops.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2020 Insolar Network Ltd. -// All rights reserved. -// This material is licensed under the Insolar License version 1.0, -// available at https://github.com/insolar/mainnet/blob/master/LICENSE.md. - -// +build debug - -package main - -import ( - "github.com/google/gops/agent" -) - -func init() { - // starts gops agent https://github.com/google/gops on default addr (127.0.0.1:0) - psAgentLauncher = func() error { - if err := agent.Listen(agent.Options{}); err != nil { - return err - } - return nil - } -} diff --git a/cmd/insolard/main.go b/cmd/insolard/main.go deleted file mode 100644 index a209a68..0000000 --- a/cmd/insolard/main.go +++ /dev/null @@ -1,252 +0,0 @@ -// Copyright 2020 Insolar Network Ltd. -// All rights reserved. -// This material is licensed under the Insolar License version 1.0, -// available at https://github.com/insolar/mainnet/blob/master/LICENSE.md. - -package main - -import ( - "encoding/json" - "github.com/insolar/mainnet/application/appfoundation" - "io/ioutil" - "path/filepath" - - "github.com/pkg/errors" - "github.com/spf13/cobra" - jww "github.com/spf13/jwalterweatherman" - - "github.com/insolar/insolar/applicationbase/genesis" - "github.com/insolar/insolar/certificate" - "github.com/insolar/insolar/configuration" - "github.com/insolar/insolar/insolar" - "github.com/insolar/insolar/log" - "github.com/insolar/insolar/logicrunner/builtin" - "github.com/insolar/insolar/server" - - "github.com/insolar/mainnet/application" - appbuiltin "github.com/insolar/mainnet/application/builtin" - "github.com/insolar/mainnet/cmd/insolard/genesisstate" -) - -func main() { - var ( - configPath string - genesisConfigPath string - heavyDB string - genesisOnly bool - ) - - var cmdHeavy = &cobra.Command{ - Use: "heavy --config=path --heavy-genesis=path", - Short: "starts heavy node", - Run: func(cmd *cobra.Command, args []string) { - runHeavyNode(configPath, genesisConfigPath, heavyDB, genesisOnly) - }, - } - cmdHeavy.Flags().StringVarP(&genesisConfigPath, "heavy-genesis", "", "", "path to genesis config for heavy node") - if err := cmdHeavy.MarkFlagRequired("heavy-genesis"); err != nil { - log.Fatal("MarkFlagRequired failed:", err) - } - cmdHeavy.Flags().StringVarP(&heavyDB, "database", "", "", "sets database type for heavy node, available badger/postgres") - if err := cmdHeavy.MarkFlagRequired("database"); err != nil { - log.Fatal("MarkFlagRequired failed:", err) - } - cmdHeavy.Flags().BoolVarP(&genesisOnly, "genesis-only", "", false, "run only genesis and then terminate") - - var cmdLight = &cobra.Command{ - Use: "light --config=path", - Short: "starts light node", - Run: func(cmd *cobra.Command, args []string) { - runLightNode(configPath) - }, - } - - var cmdVirtual = &cobra.Command{ - Use: "virtual --config=path", - Short: "starts virtual node", - Run: func(cmd *cobra.Command, args []string) { - runVirtualNode(configPath) - }, - } - - var rootCmd = &cobra.Command{ - Use: "insolard", - } - rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "path to config file") - if err := rootCmd.MarkPersistentFlagRequired("config"); err != nil { - log.Fatal("MarkFlagRequired failed:", err) - } - rootCmd.AddCommand(cmdHeavy, cmdLight, cmdVirtual) - err := rootCmd.Execute() - if err != nil { - log.Fatal("insolard execution failed:", err) - } -} - -func runHeavyNode(configPath string, genesisConfigPath string, db string, genesisOnly bool) { - var holder configuration.ConfigHolder - var err error - - switch db { - case configuration.DbTypeBadger: - holder, err = readHeavyBadgerConfig(configPath) - case configuration.DbTypePg: - holder, err = readHeavyPgConfig(configPath) - default: - log.Fatal("db type is not supported") - } - if err != nil { - log.Fatal(errors.Wrap(err, "failed to load configuration")) - } - - role, err := readRole(holder) - if err != nil { - log.Fatal(errors.Wrap(err, "readRole failed")) - } - if role != insolar.StaticRoleHeavyMaterial { - log.Fatal(errors.New("role in cert is not heavy")) - } - - if err := psAgentLauncher(); err != nil { - log.Warnf("Failed to launch gops agent: %s", err) - } - - apiOptions, err := initAPIOptions() - if err != nil { - log.Fatal(errors.Wrap(err, "failed to get API info response")) - } - - states, _ := genesisstate.InitStates(genesisConfigPath) - s := server.NewHeavyServer( - holder, - genesisConfigPath, - genesis.Options{ - States: states, - ParentDomain: application.GenesisNameRootDomain, - }, - genesisOnly, - apiOptions, - appfoundation.AllowedVersionSmartContract, - ) - s.Serve() -} - -func runVirtualNode(configPath string) { - jww.SetStdoutThreshold(jww.LevelDebug) - - holder, err := readVirtualConfig(configPath) - if err != nil { - log.Fatal(errors.Wrap(err, "failed to load configuration")) - } - - role, err := readRole(holder) - if err != nil { - log.Fatal(errors.Wrap(err, "readRole failed")) - } - if role != insolar.StaticRoleVirtual { - log.Fatal(errors.New("role in cert is not virtual executor")) - } - - if err := psAgentLauncher(); err != nil { - log.Warnf("Failed to launch gops agent: %s", err) - } - - apiOptions, err := initAPIOptions() - if err != nil { - log.Fatal(errors.Wrap(err, "failed to get API info response")) - } - - builtinContracts := builtin.BuiltinContracts{ - CodeRegistry: appbuiltin.InitializeContractMethods(), - CodeRefRegistry: appbuiltin.InitializeCodeRefs(), - CodeDescriptors: appbuiltin.InitializeCodeDescriptors(), - PrototypeDescriptors: appbuiltin.InitializePrototypeDescriptors(), - } - s := server.NewVirtualServer(holder, builtinContracts, apiOptions) - s.Serve() -} - -func runLightNode(configPath string) { - jww.SetStdoutThreshold(jww.LevelDebug) - - holder, err := readLightConfig(configPath) - if err != nil { - log.Fatal(errors.Wrap(err, "failed to load configuration")) - } - - role, err := readRole(holder) - if err != nil { - log.Fatal(errors.Wrap(err, "readRole failed")) - } - if role != insolar.StaticRoleLightMaterial { - log.Fatal(errors.New("role in cert is not light material")) - } - - apiOptions, err := initAPIOptions() - if err != nil { - log.Fatal(errors.Wrap(err, "failed to get API info response")) - } - - if err := psAgentLauncher(); err != nil { - log.Warnf("Failed to launch gops agent: %s", err) - } - - s := server.NewLightServer(holder, apiOptions) - s.Serve() -} - -// psAgentLauncher is a stub for gops agent launcher (available with 'debug' build tag) -var psAgentLauncher = func() error { return nil } - -func readHeavyBadgerConfig(path string) (*configuration.HeavyBadgerHolder, error) { - cfg := configuration.NewHeavyBadgerHolder(path) - err := cfg.Load() - if err != nil { - return nil, errors.Wrap(err, "failed to load configuration") - } - return cfg, nil -} - -func readHeavyPgConfig(path string) (*configuration.HeavyPgHolder, error) { - cfg := configuration.NewHeavyPgHolder(path) - err := cfg.Load() - if err != nil { - return nil, errors.Wrap(err, "failed to load configuration") - } - return cfg, nil -} - -func readLightConfig(path string) (*configuration.LightHolder, error) { - cfg := configuration.NewLightHolder(path) - err := cfg.Load() - if err != nil { - return nil, errors.Wrap(err, "failed to load configuration") - } - return cfg, nil -} - -func readVirtualConfig(path string) (*configuration.VirtualHolder, error) { - cfg := configuration.NewVirtualHolder(path) - err := cfg.Load() - if err != nil { - return nil, errors.Wrap(err, "failed to load configuration") - } - return cfg, nil -} - -func readRole(holder configuration.ConfigHolder) (insolar.StaticRole, error) { - data, err := ioutil.ReadFile(filepath.Clean(holder.GetGenericConfig().CertificatePath)) - if err != nil { - return insolar.StaticRoleUnknown, errors.Wrapf( - err, - "failed to read certificate from: %s", - holder.GetGenericConfig().CertificatePath, - ) - } - cert := certificate.AuthorizationCertificate{} - err = json.Unmarshal(data, &cert) - if err != nil { - return insolar.StaticRoleUnknown, errors.Wrap(err, "failed to parse certificate json") - } - return cert.GetRole(), nil -} diff --git a/cmd/insolard/testdata/bootstrap_keys.json b/cmd/insolard/testdata/bootstrap_keys.json deleted file mode 100644 index 559fdc6..0000000 --- a/cmd/insolard/testdata/bootstrap_keys.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "private_key": "-----BEGIN PRIVATE KEY-----\nMHcCAQEEIDR3m4Lvbul4pYm0h4c6O7+3LAncILXNvTZxm6/yVHVFoAoGCCqGSM49\nAwEHoUQDQgAE/kltJAtODHfdxAtn/H/TPbdPsx+G6DhdDIFrridWSphE8ejBZXGP\nwR6Rou57n4FdHVavUgm4jBrBu9fdOMXLjA==\n-----END PRIVATE KEY-----\n", - "public_key": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/kltJAtODHfdxAtn/H/TPbdPsx+G\n6DhdDIFrridWSphE8ejBZXGPwR6Rou57n4FdHVavUgm4jBrBu9fdOMXLjA==\n-----END PUBLIC KEY-----\n" -} \ No newline at end of file diff --git a/cmd/insolard/testdata/certificate.json b/cmd/insolard/testdata/certificate.json deleted file mode 100644 index ae4a78a..0000000 --- a/cmd/insolard/testdata/certificate.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "majority_rule": 0, - "public_key": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/kltJAtODHfdxAtn/H/TPbdPsx+G\n6DhdDIFrridWSphE8ejBZXGPwR6Rou57n4FdHVavUgm4jBrBu9fdOMXLjA==\n-----END PUBLIC KEY-----\n", - "reference": "insolar:1MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI", - "roles": [], - "role": "virtual", - "bootstrap_nodes": [] -} diff --git a/cmd/insolard/testdata/root_member_keys.json b/cmd/insolard/testdata/root_member_keys.json deleted file mode 100644 index ae46baf..0000000 --- a/cmd/insolard/testdata/root_member_keys.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "private_key": "-----BEGIN PRIVATE KEY-----\nMHcCAQEEIPHZvtODiQoj5X6mB0htUe1p1X2/Yi2PeBs6K/ZPgCKFoAoGCCqGSM49\nAwEHoUQDQgAEsp2gK/5k+K7IZyhxLCabU++3KM2TRSuBO8Kns4WMrw4ze6huJSPs\nOCdCGSPLMROPC6NNdDRW95l8QKlbYd8E3Q==\n-----END PRIVATE KEY-----\n", - "public_key": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEsp2gK/5k+K7IZyhxLCabU++3KM2T\nRSuBO8Kns4WMrw4ze6huJSPsOCdCGSPLMROPC6NNdDRW95l8QKlbYd8E3Q==\n-----END PUBLIC KEY-----\n" -} \ No newline at end of file diff --git a/go.mod b/go.mod index 1ec9f15..4256bc4 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.com/insolar/mainnet go 1.15 require ( - github.com/google/gops v0.3.6 + github.com/google/gops v0.3.6 // indirect github.com/insolar/insolar v1.9.0 github.com/insolar/x-crypto v0.0.0-20191031140942-75fab8a325f6 github.com/pkg/errors v0.9.1 github.com/spf13/cobra v0.0.5 - github.com/spf13/jwalterweatherman v1.1.0 + github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.6.2 github.com/stretchr/testify v1.4.0