public void Execute(bool invalid, bool pendingExist, bool alreadyActivated, Type exc) { var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var privateKey = new PrivateKey(); (ActivationKey activationKey, PendingActivationState pendingActivation) = ActivationKey.Create(privateKey, nonce); Address activatedAddress = default(Address).Derive(ActivationKey.DeriveKey); var state = new State(); if (pendingExist) { state = (State)state.SetState(pendingActivation.address, pendingActivation.Serialize()); } if (alreadyActivated) { state = (State)state.SetState(activatedAddress, true.Serialize()); } ActivateAccount action = activationKey.CreateActivateAccount(invalid ? new byte[] { 0x00 } : nonce); if (exc is null) { IAccountStateDelta nextState = action.Execute(new ActionContext() { PreviousStates = state, Signer = default,
public ActivationStatusMutation() { Field <NonNullGraphType <BooleanGraphType> >("activateAccount", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "encodedActivationKey", }), resolve: context => { try { string encodedActivationKey = context.GetArgument <string>("encodedActivationKey"); NineChroniclesNodeService service = context.Source; // FIXME: Private key may not exists at this moment. PrivateKey privateKey = service.PrivateKey; ActivationKey activationKey = ActivationKey.Decode(encodedActivationKey); BlockChain <NineChroniclesActionType> blockChain = service.Swarm.BlockChain; IValue state = blockChain.GetState(activationKey.PendingAddress); if (!(state is Bencodex.Types.Dictionary asDict)) { context.Errors.Add(new ExecutionError("The given key was already expired.")); return(false); } var pendingActivationState = new PendingActivationState(asDict); ActivateAccount action = activationKey.CreateActivateAccount( pendingActivationState.Nonce); var actions = new NineChroniclesActionType[] { action }; blockChain.MakeTransaction(privateKey, actions); }
public async Task ActivateAccount() { var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var privateKey = new PrivateKey(); (ActivationKey activationKey, PendingActivationState pendingActivation) = ActivationKey.Create(privateKey, nonce); PolymorphicAction <ActionBase> action = new CreatePendingActivation(pendingActivation); BlockChain.MakeTransaction(AdminPrivateKey, new[] { action }); await BlockChain.MineBlock(AdminAddress); var encodedActivationKey = activationKey.Encode(); var queryResult = await ExecuteQueryAsync( $"mutation {{ activationStatus {{ activateAccount(encodedActivationKey: \"{encodedActivationKey}\") }} }}"); await BlockChain.MineBlock(AdminAddress); var result = (bool)queryResult.Data .As <Dictionary <string, object> >()["activationStatus"] .As <Dictionary <string, object> >()["activateAccount"]; Assert.True(result); var state = (Bencodex.Types.Dictionary)BlockChain.GetState( ActivatedAccountsState.Address); var activatedAccountsState = new ActivatedAccountsState(state); Address userAddress = StandaloneContextFx.NineChroniclesNodeService !.MinerPrivateKey !.ToAddress(); Assert.True(activatedAccountsState.Accounts.Contains(userAddress)); }
private Block <PolymorphicAction <ActionBase> > MakeGenesisBlock( Address adminAddress, IImmutableSet <Address> activatedAddresses, AuthorizedMinersState authorizedMinersState = null, DateTimeOffset?timestamp = null, PendingActivationState[] pendingActivations = null ) { if (pendingActivations is null) { var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; (ActivationKey activationKey, PendingActivationState pendingActivation) = ActivationKey.Create(_privateKey, nonce); pendingActivations = new[] { pendingActivation }; } var sheets = TableSheetsImporter.ImportSheets(); return(BlockHelper.MineGenesisBlock( sheets, new GoldDistribution[0], pendingActivations, new AdminState(adminAddress, 1500000), authorizedMinersState: authorizedMinersState, activatedAccounts: activatedAddresses, isActivateAdminAddress: false, credits: null, privateKey: _privateKey, timestamp: timestamp ?? DateTimeOffset.MinValue)); }
public void ActivateAccount(bool invalid, int expectedCode) { var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var privateKey = new PrivateKey(); (ActivationKey activationKey, PendingActivationState _) = ActivationKey.Create(privateKey, nonce); string invitationCode = invalid ? "invalid_code" : activationKey.Encode(); var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); var resultCode = _command.ActivateAccount(invitationCode, ByteUtil.Hex(nonce), filePath); Assert.Equal(expectedCode, resultCode); if (resultCode == 0) { var rawAction = Convert.FromBase64String(File.ReadAllText(filePath)); var decoded = (List)_codec.Decode(rawAction); string type = (Text)decoded[0]; Assert.Equal(nameof(Nekoyume.Action.ActivateAccount), type); Dictionary plainValue = (Dictionary)decoded[1]; var action = new ActivateAccount(); action.LoadPlainValue(plainValue); Assert.Equal(activationKey.PrivateKey.Sign(nonce), action.Signature); Assert.Equal(activationKey.PendingAddress, action.PendingAddress); } else { Assert.Contains("hexWithSlash seems invalid. [invalid_code]", _console.Error.ToString()); } }
public int ActivateAccount( [Argument("INVITATION-CODE", Description = "An invitation code.")] string invitationCode, [Argument("NONCE", Description = "A hex-encoded nonce for activation.")] string nonceEncoded, [Argument("PATH", Description = "A file path of base64 encoded action.")] string filePath ) { try { ActivationKey activationKey = ActivationKey.Decode(invitationCode); byte[] nonce = ByteUtil.ParseHex(nonceEncoded); Nekoyume.Action.ActivateAccount action = activationKey.CreateActivateAccount(nonce); var encoded = new List( new[] { (Text)nameof(Nekoyume.Action.ActivateAccount), action.PlainValue } ); byte[] raw = Codec.Encode(encoded); File.WriteAllText(filePath, Convert.ToBase64String(raw)); return(0); } catch (Exception e) { _console.Error.WriteLine(e); return(-1); } }
protected void ButtonRestore_Click(object sender, EventArgs e) { if (TextBoxRestoreCaptcha.Text.ToLower() != this.Session["CaptchaImageText"].ToString().ToLower()) { LabelRestoreError.Visible = true; LabelRestoreError.Text = "Введён неправильный секретный код"; TextBoxRestoreCaptcha.Text = String.Empty; this.Session["CaptchaImageText"] = GenerateRandomCode(); return; } using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString)) { var user = dataContext.Users.Where(c => c.Email == TextBoxRestore.Text.Trim().ToLower()).FirstOrDefault(); if (user == null) { LabelRestoreError.Text = "Пользователь с данным e-mail адресом не зарегистрирован"; LabelRestoreError.Visible = true; return; } else { ActivationKey key = new ActivationKey(); key.ActivationKey1 = Guid.NewGuid().ToString(); key.UserId = user.UserId; dataContext.ActivationKeys.InsertOnSubmit(key); dataContext.SubmitChanges(); SendRestoreMail(user.Email, key.ActivationKey1, user.Login); MultiView1.ActiveViewIndex = 3; } } }
public void Decode() { string encoded = "ac84ad2eb0bc62c63e8c4e4f22f7c19d283b36e60fdc4eed182d4d7a7bb4c716/46c4365d645647791768b9a9e6e4a9376b15c643"; ActivationKey ak = ActivationKey.Decode(encoded); Assert.Equal(new Address("46c4365d645647791768b9a9e6e4a9376b15c643"), ak.PendingAddress); Assert.Equal(new PrivateKey(ByteUtil.ParseHex("ac84ad2eb0bc62c63e8c4e4f22f7c19d283b36e60fdc4eed182d4d7a7bb4c716")), ak.PrivateKey); }
public void ValidateNextBlockTxWithAuthorizedMiners() { var adminPrivateKey = new PrivateKey(); var adminAddress = adminPrivateKey.ToAddress(); var authorizedMinerPrivateKey = new PrivateKey(); (ActivationKey ak, PendingActivationState ps) = ActivationKey.Create( new PrivateKey(), new byte[] { 0x00, 0x01 } ); var blockPolicySource = new BlockPolicySource(Logger.None); IBlockPolicy <PolymorphicAction <ActionBase> > policy = blockPolicySource.GetPolicy( minimumDifficulty: 10_000, hashAlgorithmTypePolicy: null, maxBlockBytesPolicy: null, minTransactionsPerBlockPolicy: null, maxTransactionsPerBlockPolicy: null, maxTransactionsPerSignerPerBlockPolicy: null, authorizedMinersPolicy: AuthorizedMinersPolicy .Default .Add(new SpannedSubPolicy <ImmutableHashSet <Address> >( startIndex: 0, endIndex: 10, filter: index => index % 5 == 0, value: new Address[] { authorizedMinerPrivateKey.ToAddress() } .ToImmutableHashSet())), permissionedMinersPolicy: null); IStagePolicy <PolymorphicAction <ActionBase> > stagePolicy = new VolatileStagePolicy <PolymorphicAction <ActionBase> >(); Block <PolymorphicAction <ActionBase> > genesis = MakeGenesisBlock( adminAddress, ImmutableHashSet.Create(adminAddress), pendingActivations: new[] { ps } ); using var store = new DefaultStore(null); using var stateStore = new TrieStateStore(new DefaultKeyValueStore(null)); var blockChain = new BlockChain <PolymorphicAction <ActionBase> >( policy, stagePolicy, store, stateStore, genesis, renderers: new[] { blockPolicySource.BlockRenderer } ); Transaction <PolymorphicAction <ActionBase> > txFromAuthorizedMiner = Transaction <PolymorphicAction <ActionBase> > .Create( 0, authorizedMinerPrivateKey, genesis.Hash, new PolymorphicAction <ActionBase>[] { ak.CreateActivateAccount(new byte[] { 0x00, 0x01 }) } ); // Deny tx even if contains valid activation key. Assert.NotNull(policy.ValidateNextBlockTx(blockChain, txFromAuthorizedMiner)); }
public void Encode() { var privateKey = new PrivateKey(ByteUtil.ParseHex("ac84ad2eb0bc62c63e8c4e4f22f7c19d283b36e60fdc4eed182d4d7a7bb4c716")); var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; (ActivationKey ak, var _) = ActivationKey.Create(privateKey, nonce); Assert.Equal("ac84ad2eb0bc62c63e8c4e4f22f7c19d283b36e60fdc4eed182d4d7a7bb4c716/46c4365d645647791768b9a9e6e4a9376b15c643", ak.Encode()); }
public async Task <ActionResult> DeleteConfirmed(long id) { ActivationKey activationKey = await db.ActivationKeys.FindAsync(id); db.ActivationKeys.Remove(activationKey); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "Id,DateOfPurchase,UserId,Key,KeyNumber")] ActivationKey activationKey) { if (ModelState.IsValid) { db.Entry(activationKey).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(activationKey)); }
public IActionResult GetDate([FromBody] AtvKeyInput input) { ActivationKey ak = db.ActivationKeys.Where(x => x.PdtAtvKey == input.AtvKey).FirstOrDefault(); PurchaseDetail p = db.PurchaseDetails.Where(x => x.PurchaseId == ak.PurchaseDetailPurchaseId && x.ProductId == ak.PurchaseDetailProductId).FirstOrDefault(); var dateFormat = "dd MMM yyyy"; DateTimeOffset pdatetime = DateTimeOffset.FromUnixTimeSeconds(p.Purchase.Timestamp).ToLocalTime(); string pdate = pdatetime.ToString(dateFormat); return(Json(new { pdate, pdtId = p.ProductId })); }
public void Create() { var privateKey = new PrivateKey(ByteUtil.ParseHex("ac84ad2eb0bc62c63e8c4e4f22f7c19d283b36e60fdc4eed182d4d7a7bb4c716")); var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; (ActivationKey ak, PendingActivationState pending) = ActivationKey.Create(privateKey, nonce); Assert.Equal(privateKey, ak.PrivateKey); Assert.Equal(pending.address, ak.PendingAddress); Assert.Equal(privateKey.PublicKey, pending.PublicKey); Assert.Equal(nonce, pending.Nonce); }
public async Task <ActionResult> Create([Bind(Include = "Id,DateOfPurchase,UserId,Key,KeyNumber")] ActivationKey activationKey) { if (ModelState.IsValid) { db.ActivationKeys.Add(activationKey); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(activationKey)); }
public async void EarnMiningGoldWhenSuccessMining() { var adminPrivateKey = new PrivateKey(); var adminAddress = adminPrivateKey.ToAddress(); var authorizedMinerPrivateKey = new PrivateKey(); (ActivationKey ak, PendingActivationState ps) = ActivationKey.Create( new PrivateKey(), new byte[] { 0x00, 0x01 } ); var blockPolicySource = new BlockPolicySource(Logger.None); IBlockPolicy <PolymorphicAction <ActionBase> > policy = blockPolicySource.GetPolicy( 10_000, null, null, null, null, null, null, null); IStagePolicy <PolymorphicAction <ActionBase> > stagePolicy = new VolatileStagePolicy <PolymorphicAction <ActionBase> >(); Block <PolymorphicAction <ActionBase> > genesis = MakeGenesisBlock( adminAddress, ImmutableHashSet.Create(adminAddress), new AuthorizedMinersState( new[] { authorizedMinerPrivateKey.ToAddress() }, 5, 10 ), pendingActivations: new[] { ps } ); using var store = new DefaultStore(null); using var stateStore = new TrieStateStore(new DefaultKeyValueStore(null)); var blockChain = new BlockChain <PolymorphicAction <ActionBase> >( policy, stagePolicy, store, stateStore, genesis, renderers: new[] { blockPolicySource.BlockRenderer } ); blockChain.MakeTransaction( adminPrivateKey, new PolymorphicAction <ActionBase>[] { new DailyReward(), } ); await blockChain.MineBlock(adminPrivateKey); FungibleAssetValue actualBalance = blockChain.GetBalance(adminAddress, _currency); FungibleAssetValue expectedBalance = new FungibleAssetValue(_currency, 10, 0); Assert.True(expectedBalance.Equals(actualBalance)); }
// GET: ActivationKeys/Delete/5 public async Task <ActionResult> Delete(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ActivationKey activationKey = await db.ActivationKeys.FindAsync(id); if (activationKey == null) { return(HttpNotFound()); } return(View(activationKey)); }
public void CreateActivationKeys(UserSubscription userSubscription) { switch (userSubscription.Subscription.SubscriptionType) { case SubscriptionTypes.Student: var studentActivationKey = new ActivationKey() { ActivationKeyType = ActivationKeyTypes.Student }; userSubscription.ActivationKeys.Add(studentActivationKey); _context.ActivationKeys.Add(studentActivationKey); // needed? break; case SubscriptionTypes.Family: var familyActivationKey = new ActivationKey() { ActivationKeyType = ActivationKeyTypes.Family }; userSubscription.ActivationKeys.Add(familyActivationKey); for (var i = 1; i < 5; i++) { var studentActivationKeyInFamily = new ActivationKey() { ActivationKeyType = ActivationKeyTypes.Student }; userSubscription.ActivationKeys.Add(studentActivationKeyInFamily); _context.ActivationKeys.Add(studentActivationKeyInFamily); // needed? } break; case SubscriptionTypes.Class: var classActivationKey = new ActivationKey() { ActivationKeyType = ActivationKeyTypes.Class }; userSubscription.ActivationKeys.Add(classActivationKey); for (var i = 1; i < 31; i++) { var studentActivationKeyInClass = new ActivationKey() { ActivationKeyType = ActivationKeyTypes.Student }; userSubscription.ActivationKeys.Add(studentActivationKeyInClass); _context.ActivationKeys.Add(studentActivationKeyInClass); // needed? } break; } }
public void DoesTransactionFollowsPolicyWithAuthorizedMiners() { var adminPrivateKey = new PrivateKey(); var adminAddress = adminPrivateKey.ToAddress(); var authorizedMinerPrivateKey = new PrivateKey(); (ActivationKey ak, PendingActivationState ps) = ActivationKey.Create( new PrivateKey(), new byte[] { 0x00, 0x01 } ); var blockPolicySource = new BlockPolicySource(Logger.None); IBlockPolicy <PolymorphicAction <ActionBase> > policy = blockPolicySource.GetPolicy(10000, 100); IStagePolicy <PolymorphicAction <ActionBase> > stagePolicy = new VolatileStagePolicy <PolymorphicAction <ActionBase> >(); Block <PolymorphicAction <ActionBase> > genesis = MakeGenesisBlock( adminAddress, ImmutableHashSet.Create(adminAddress), new AuthorizedMinersState( new[] { authorizedMinerPrivateKey.ToAddress() }, 5, 10 ), pendingActivations: new[] { ps } ); using var store = new DefaultStore(null); using var stateStore = new TrieStateStore(new DefaultKeyValueStore(null), new DefaultKeyValueStore(null)); var blockChain = new BlockChain <PolymorphicAction <ActionBase> >( policy, stagePolicy, store, stateStore, genesis, renderers: new[] { blockPolicySource.BlockRenderer } ); Transaction <PolymorphicAction <ActionBase> > txFromAuthorizedMiner = Transaction <PolymorphicAction <ActionBase> > .Create( 0, authorizedMinerPrivateKey, genesis.Hash, new PolymorphicAction <ActionBase>[] { ak.CreateActivateAccount(new byte[] { 0x00, 0x01 }) } ); // Deny tx even if contains valid activation key. Assert.False(policy.DoesTransactionFollowsPolicy(txFromAuthorizedMiner, blockChain)); }
public void Execute() { var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var privateKey = new PrivateKey(); (ActivationKey activationKey, PendingActivationState pendingActivation) = ActivationKey.Create(privateKey, nonce); var state = new State(ImmutableDictionary <Address, IValue> .Empty .Add(ActivatedAccountsState.Address, new ActivatedAccountsState().Serialize()) .Add(pendingActivation.address, pendingActivation.Serialize())); ActivateAccount0 action = activationKey.CreateActivateAccount0(nonce); IAccountStateDelta nextState = action.Execute(new ActionContext() { PreviousStates = state, Signer = default,
public void MustNotIncludeBlockActionAtTransaction() { var adminPrivateKey = new PrivateKey(); var adminAddress = adminPrivateKey.ToAddress(); var authorizedMinerPrivateKey = new PrivateKey(); (ActivationKey ak, PendingActivationState ps) = ActivationKey.Create( new PrivateKey(), new byte[] { 0x00, 0x01 } ); var blockPolicySource = new BlockPolicySource(Logger.None); IBlockPolicy <PolymorphicAction <ActionBase> > policy = blockPolicySource.GetPolicy( 10_000, null, null, null, null, null, null, null); IStagePolicy <PolymorphicAction <ActionBase> > stagePolicy = new VolatileStagePolicy <PolymorphicAction <ActionBase> >(); Block <PolymorphicAction <ActionBase> > genesis = MakeGenesisBlock( adminAddress, ImmutableHashSet.Create(adminAddress), new AuthorizedMinersState( new[] { authorizedMinerPrivateKey.ToAddress() }, 5, 10 ), pendingActivations: new[] { ps } ); using var store = new DefaultStore(null); using var stateStore = new TrieStateStore(new DefaultKeyValueStore(null)); var blockChain = new BlockChain <PolymorphicAction <ActionBase> >( policy, stagePolicy, store, stateStore, genesis, renderers: new[] { blockPolicySource.BlockRenderer } ); Assert.Throws <MissingActionTypeException>(() => { blockChain.MakeTransaction( adminPrivateKey, new PolymorphicAction <ActionBase>[] { new RewardGold() } ); }); }
private ActivationKey CheckProductRenewalOnActivationServer(string productKey) { try { string connectionStringName = DbCommandUtil.GetActivationConnectionString(); var dbContext = new EntitiesModel(connectionStringName); ActivationKey key = dbContext.ActivationKeys .FirstOrDefault(a => a.ProductKey == productKey && a.KeyStatus == 0 && a.ProductType == 0); return(key); } catch { return(null); } }
public long RegisterKey(ActivationKeyCreateModel model, string createdBy) { var intention = this.FindIntentionById(model.IntentionId); var key = new ActivationKey() { CreatedBy = createdBy, Name = model.Name, IntentionId = intention.Id, Intention = intention }; this.Data.ActivationKeyRepository.Add(key); this.Data.SaveChanges(); return(intention.Id); }
private static void CreateActivationKey( out List <PendingActivationState> pendingActivationStates, out List <ActivationKey> activationKeys, int countOfKeys) { pendingActivationStates = new List <PendingActivationState>(); activationKeys = new List <ActivationKey>(); for (int i = 0; i < countOfKeys; i++) { var pendingKey = new PrivateKey(); var nonce = pendingKey.PublicKey.ToAddress().ToByteArray(); (ActivationKey ak, PendingActivationState s) = ActivationKey.Create(pendingKey, nonce); pendingActivationStates.Add(s); activationKeys.Add(ak); } }
public async Task ActivateAccount() { var adminPrivateKey = new PrivateKey(); var adminAddress = adminPrivateKey.ToAddress(); var activateAccounts = new[] { adminAddress }.ToImmutableHashSet(); Block <PolymorphicAction <ActionBase> > genesis = MakeGenesisBlock(adminAddress, new Currency("NCG", 2, minters: null), activateAccounts); NineChroniclesNodeService service = ServiceBuilder.CreateNineChroniclesNodeService(genesis); StandaloneContextFx.NineChroniclesNodeService = service; StandaloneContextFx.BlockChain = service.Swarm.BlockChain; var blockChain = StandaloneContextFx.BlockChain; var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var privateKey = new PrivateKey(); (ActivationKey activationKey, PendingActivationState pendingActivation) = ActivationKey.Create(privateKey, nonce); PolymorphicAction <ActionBase> action = new CreatePendingActivation(pendingActivation); blockChain.MakeTransaction(adminPrivateKey, new[] { action }); await blockChain.MineBlock(adminAddress); var encodedActivationKey = activationKey.Encode(); var queryResult = await ExecuteQueryAsync( $"mutation {{ activationStatus {{ activateAccount(encodedActivationKey: \"{encodedActivationKey}\") }} }}"); await blockChain.MineBlock(adminAddress); var result = (bool)queryResult.Data .As <Dictionary <string, object> >()["activationStatus"] .As <Dictionary <string, object> >()["activateAccount"]; Assert.True(result); var state = (Bencodex.Types.Dictionary)blockChain.GetState( ActivatedAccountsState.Address); var activatedAccountsState = new ActivatedAccountsState(state); Address userAddress = service.PrivateKey.ToAddress(); Assert.True(activatedAccountsState.Accounts.Contains(userAddress)); }
private Block<PolymorphicAction<ActionBase>> MakeGenesisBlock( Address adminAddress, IImmutableSet<Address> activatedAddresses, AuthorizedMinersState authorizedMinersState = null, DateTimeOffset? timestamp = null, PendingActivationState[] pendingActivations = null ) { if (pendingActivations is null) { var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var privateKey = new PrivateKey(); (ActivationKey activationKey, PendingActivationState pendingActivation) = ActivationKey.Create(privateKey, nonce); pendingActivations = new[] { pendingActivation }; } return BlockChain<PolymorphicAction<ActionBase>>.MakeGenesisBlock( new PolymorphicAction<ActionBase>[] { new InitializeStates( rankingState: new RankingState(), shopState: new ShopState(), tableSheets: TableSheetsImporter.ImportSheets(), gameConfigState: new GameConfigState(), redeemCodeState: new RedeemCodeState(Dictionary.Empty .Add("address", RedeemCodeState.Address.Serialize()) .Add("map", Dictionary.Empty) ), adminAddressState: new AdminState(adminAddress, 1500000), activatedAccountsState: new ActivatedAccountsState(activatedAddresses), goldCurrencyState: new GoldCurrencyState( new Currency("NCG", 2, minter: null) ), goldDistributions: new GoldDistribution[0], pendingActivationStates: pendingActivations, authorizedMinersState: authorizedMinersState ), }, timestamp: timestamp ?? DateTimeOffset.MinValue ); }
public ActivationStatusMutation(NineChroniclesNodeService service) { Field <NonNullGraphType <BooleanGraphType> >("activateAccount", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "encodedActivationKey", }), resolve: context => { try { string encodedActivationKey = context.GetArgument <string>("encodedActivationKey"); // FIXME: Private key may not exists at this moment. if (!(service.MinerPrivateKey is { } privateKey)) { throw new InvalidOperationException($"{nameof(privateKey)} is null."); } ActivationKey activationKey = ActivationKey.Decode(encodedActivationKey); if (!(service.Swarm?.BlockChain is { } blockChain)) { throw new InvalidOperationException($"{nameof(blockChain)} is null."); } IValue state = blockChain.GetState(activationKey.PendingAddress); if (!(state is Bencodex.Types.Dictionary asDict)) { context.Errors.Add(new ExecutionError("The given key was already expired.")); return(false); } var pendingActivationState = new PendingActivationState(asDict); ActivateAccount action = activationKey.CreateActivateAccount( pendingActivationState.Nonce); var actions = new NCAction[] { action }; blockChain.MakeTransaction(privateKey, actions); }
public static void CreateActivationKey( out List <PendingActivationState> pendingActivationStates, out List <ActivationKey> activationKeys, uint countOfKeys) { var ps = new ConcurrentBag <PendingActivationState>(); var ks = new ConcurrentBag <ActivationKey>(); Parallel.For(0, countOfKeys, _ => { var pendingKey = new PrivateKey(); var nonce = pendingKey.PublicKey.ToAddress().ToByteArray(); (ActivationKey ak, PendingActivationState s) = ActivationKey.Create(pendingKey, nonce); ps.Add(s); ks.Add(ak); }); pendingActivationStates = ps.ToList(); activationKeys = ks.ToList(); }
public void BuyActivationKey() { string userId = User.Identity.GetUserId(); var lastKey = (from key in DbContext.ActivationKeys where key.UserId == userId orderby key.KeyNumber descending select key).FirstOrDefault(); if (lastKey == null) { ActivationKey newKey = new ActivationKey { DateOfPurchase = DateTime.Now, Key = keyProviders[new Random().Next(0, keyProviders.Count)].CreateKey(User.Identity.Name, 1), UserId = User.Identity.GetUserId(), KeyNumber = 1 }; DbContext.ActivationKeys.Add(newKey); DbContext.SaveChanges(); } else { ActivationKey newKey = new ActivationKey { DateOfPurchase = DateTime.Now, Key = keyProviders[new Random().Next(0, keyProviders.Count)].CreateKey(User.Identity.Name, lastKey.KeyNumber + 1), UserId = User.Identity.GetUserId(), KeyNumber = lastKey.KeyNumber + 1 }; DbContext.ActivationKeys.Add(newKey); DbContext.SaveChanges(); } Redirect("Index"); }
public void Execute() { var gameConfigState = new GameConfigState(_sheets[nameof(GameConfigSheet)]); var redeemCodeListSheet = new RedeemCodeListSheet(); redeemCodeListSheet.Set(_sheets[nameof(RedeemCodeListSheet)]); var goldDistributionCsvPath = GoldDistributionTest.CreateFixtureCsvFile(); var goldDistributions = GoldDistribution.LoadInDescendingEndBlockOrder(goldDistributionCsvPath); var minterKey = new PrivateKey(); var ncg = new Currency("NCG", 2, minterKey.ToAddress()); var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var privateKey = new PrivateKey(); (ActivationKey activationKey, PendingActivationState pendingActivation) = ActivationKey.Create(privateKey, nonce); var action = new InitializeStates( rankingState: new RankingState(), shopState: new ShopState(), tableSheets: _sheets, gameConfigState: gameConfigState, redeemCodeState: new RedeemCodeState(redeemCodeListSheet), adminAddressState: new AdminState( new Address("F9A15F870701268Bd7bBeA6502eB15F4997f32f9"), 1500000 ), activatedAccountsState: new ActivatedAccountsState(), goldCurrencyState: new GoldCurrencyState(ncg), goldDistributions: goldDistributions, pendingActivationStates: new[] { pendingActivation } ); var genesisState = action.Execute(new ActionContext() { BlockIndex = 0, Miner = default,