public override IAccountStateDelta Execute(IActionContext context) { IAccountStateDelta state = context.PreviousStates; if (context.Rehearsal) { return(state .SetState(ActivatedAccountsState.Address, MarkChanged)); } if (!state.TryGetState(ActivatedAccountsState.Address, out Dictionary accountsAsDict)) { throw new ActivatedAccountsDoesNotExistsException(); } CheckObsolete(BlockChain.Policy.BlockPolicySource.V100080ObsoleteIndex, context); CheckPermission(context); var accounts = new ActivatedAccountsState(accountsAsDict); return(state.SetState( ActivatedAccountsState.Address, accounts.AddAccount(Address).Serialize() )); }
public override IAccountStateDelta Execute(IActionContext context) { IAccountStateDelta state = context.PreviousStates; if (context.Rehearsal) { return(state .SetState(ActivatedAccountsState.Address, MarkChanged) .SetState(PendingAddress, MarkChanged)); } CheckObsolete(BlockChain.Policy.BlockPolicySource.V100080ObsoleteIndex, context); if (!state.TryGetState(ActivatedAccountsState.Address, out Dictionary accountsAsDict)) { throw new ActivatedAccountsDoesNotExistsException(); } if (!state.TryGetState(PendingAddress, out Dictionary pendingAsDict)) { throw new PendingActivationDoesNotExistsException(PendingAddress); } var accounts = new ActivatedAccountsState(accountsAsDict); var pending = new PendingActivationState(pendingAsDict); if (pending.Verify(Signature)) { // We left this log message to track activation history. // Please delete it if we have an API for evaluation results on the Libplanet side. Log.Information("{pendingAddress} is activated by {signer} now.", pending.address, context.Signer); return(state.SetState( ActivatedAccountsState.Address, accounts.AddAccount(context.Signer).Serialize() ).SetState( pending.address, new Bencodex.Types.Null() )); } else { throw new InvalidSignatureException(pending, Signature); } }
public override IAccountStateDelta Execute(IActionContext context) { IAccountStateDelta state = context.PreviousStates; if (context.Rehearsal) { return(state .SetState(ActivatedAccountsState.Address, MarkChanged) .SetState(PendingAddress, MarkChanged)); } if (!state.TryGetState(ActivatedAccountsState.Address, out Dictionary accountsAsDict)) { throw new ActivatedAccountsDoesNotExistsException(); } if (!state.TryGetState(PendingAddress, out Dictionary pendingAsDict)) { throw new PendingActivationDoesNotExistsException(PendingAddress); } var accounts = new ActivatedAccountsState(accountsAsDict); var pending = new PendingActivationState(pendingAsDict); if (pending.Verify(this)) { return(state.SetState( ActivatedAccountsState.Address, accounts.AddAccount(context.Signer).Serialize() ).SetState( pending.address, new Bencodex.Types.Null() )); } else { throw new InvalidSignatureException(pending, Signature); } }