private bool Asset_Renew(ExecutionEngine engine) { AssetState asset = engine.EvaluationStack.Pop().GetInterface <AssetState>(); if (asset == null) { return(false); } byte years = (byte)engine.EvaluationStack.Pop().GetBigInteger(); asset = assets.GetAndChange(asset.AssetId); if (asset.Expiration < Blockchain.Default.Height + 1) { asset.Expiration = Blockchain.Default.Height + 1; } try { asset.Expiration = checked (asset.Expiration + years * 2000000u); } catch (OverflowException) { asset.Expiration = uint.MaxValue; } engine.EvaluationStack.Push(asset.Expiration); return(true); }
private bool Account_SetVotes(ExecutionEngine engine) { AccountState account = engine.EvaluationStack.Pop().GetInterface <AccountState>(); ECPoint[] votes = engine.EvaluationStack.Pop().GetArray().Select(p => ECPoint.DecodePoint(p.GetByteArray(), ECCurve.Secp256r1)).ToArray(); if (account == null) { return(false); } if (votes.Length > 1024) { return(false); } account = accounts[account.ScriptHash]; if (account.IsFrozen) { return(false); } if ((!account.Balances.TryGetValue(Blockchain.GoverningToken.Hash, out Fixed8 balance) || balance.Equals(Fixed8.Zero)) && votes.Length > 0) { return(false); } if (!CheckWitness(engine, account.ScriptHash)) { return(false); } account = accounts.GetAndChange(account.ScriptHash); account.Votes = votes.Distinct().ToArray(); return(true); }
private bool Storage_Put(ExecutionEngine engine) { StorageContext context = engine.EvaluationStack.Pop().GetInterface <StorageContext>(); if (!CheckStorageContext(context)) { return(false); } byte[] key = engine.EvaluationStack.Pop().GetByteArray(); if (key.Length > 1024) { return(false); } byte[] value = engine.EvaluationStack.Pop().GetByteArray(); storages.GetAndChange(new StorageKey { ScriptHash = context.ScriptHash, Key = key }, () => new StorageItem()).Value = value; return(true); }