protected bool Storage_Get(ExecutionEngine engine) { CustomStorageContext context = engine.EvaluationStack.Pop().GetInterface <CustomStorageContext>(); byte[] key = engine.EvaluationStack.Pop().GetByteArray(); StorageItem item = new StorageItem { Value = (byte[])context.data[Encoding.UTF8.GetString(key)] }; engine.EvaluationStack.Push(item?.Value ?? new byte[0]); return(true); }
protected bool Storage_Put(ExecutionEngine engine) { CustomStorageContext context = engine.EvaluationStack.Pop().GetInterface <CustomStorageContext>(); byte[] key = engine.EvaluationStack.Pop().GetByteArray(); if (key.Length > 1024) { return(false); } byte[] value = engine.EvaluationStack.Pop().GetByteArray(); context.data[Encoding.UTF8.GetString(key)] = value; return(true); }
public CustomInteropService() { Register("Neo.Storage.GetContext", Storage_GetContext); Register("Neo.Storage.Get", Storage_Get); Register("Neo.Storage.Put", Storage_Put); Register("Neo.Runtime.CheckWitness", Runtime_CheckWitness); Register("Neo.Transaction.GetInputs", Transaction_GetInputs); Register("Neo.Transaction.GetOutputs", Transaction_GetOutputs); Register("Neo.Blockchain.GetTransaction", Blockchain_GetTransaction); Register("Neo.Input.GetHash", Input_GetHash); Register("Neo.Input.GetIndex", Input_GetIndex); Register("Neo.Output.GetScriptHash", Output_GetScriptHash); Register("Neo.Runtime.Notify", Runtime_Notify); this.storageContext = new CustomStorageContext(); this.transactions = new Hashtable(); }