private static ExecutionState Map_Set(RuntimeVM vm) { vm.ExpectStackSize(3); // for security reasons we don't accept the caller to specify a contract name var contractName = vm.CurrentContext.Name; vm.Expect(vm.ContractDeployed(contractName), $"contract {contractName} is not deployed"); var field = vm.PopString("field"); var mapKey = SmartContract.GetKeyForField(contractName, field, false); var entry_obj = vm.Stack.Pop(); var entryKey = entry_obj.AsByteArray(); vm.Expect(entryKey.Length > 0, "invalid entry key"); var value = vm.Stack.Pop(); var map = new StorageMap(mapKey, vm.Storage); var value_bytes = value.AsByteArray(); map.SetRaw(entryKey, value_bytes); return(ExecutionState.Running); }
private static ExecutionState Data_Get(RuntimeVM vm) { vm.ExpectStackSize(3); var contractName = vm.PopString("contract"); vm.Expect(vm.ContractDeployed(contractName), $"contract {contractName} is not deployed"); var field = vm.PopString("field"); var key = SmartContract.GetKeyForField(contractName, field, false); var type_obj = vm.Stack.Pop(); var vmType = type_obj.AsEnum <VMType>(); if (vmType == VMType.Object) { vmType = VMType.Bytes; } var value_bytes = vm.Storage.Get(key); var val = new VMObject(); val.SetValue(value_bytes, vmType); vm.Stack.Push(val); return(ExecutionState.Running); }
private static ExecutionState Data_Delete(RuntimeVM vm) { vm.ExpectStackSize(1); // for security reasons we don't accept the caller to specify a contract name var contractName = vm.CurrentContext.Name; vm.Expect(vm.ContractDeployed(contractName), $"contract {contractName} is not deployed"); var field = vm.PopString("field"); var key = SmartContract.GetKeyForField(contractName, field, false); var contractAddress = SmartContract.GetAddressForName(contractName); vm.CallNativeContext(NativeContractKind.Storage, nameof(StorageContract.DeleteData), contractAddress, key); return(ExecutionState.Running); }