Skip to content

Instantly share code, notes, and snippets.

@hal0x2328
Created August 28, 2019 14:38
Show Gist options
  • Save hal0x2328/32671046d7186f49b6e1d6f23eb3ad85 to your computer and use it in GitHub Desktop.
Save hal0x2328/32671046d7186f49b6e1d6f23eb3ad85 to your computer and use it in GitHub Desktop.
Simple Neo Supply Chain Smart Contract Example
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;
using Neo.SmartContract.Framework.Services.System;
// simple supply chain tracking contract example
namespace Neo.SmartContract
{
public struct TrackedItem
{
public byte[] ID;
public string Payload;
public uint Timestamp;
}
public class Tracker : Framework.SmartContract
{
private static readonly byte[] Owner = "AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y".ToScriptHash();
public static object Main(string operation, object[] args)
{
if (operation == "putdata")
{
if (Runtime.CheckWitness(Owner))
{
Transaction tx = ExecutionEngine.ScriptContainer as Transaction;
string payload = args[0] as string;
uint timestamp = Runtime.Time;
TrackedItem item = new TrackedItem
{
ID = tx.Hash,
Payload = payload,
Timestamp = timestamp
};
Storage.Put(tx.Hash, item.Serialize());
return true;
}
return false;
}
if (operation == "getpayload")
{
byte[] id = args[0] as byte[];
TrackedItem item = (TrackedItem)Framework.Helper.Deserialize(Storage.Get(id));
return item.Payload;
}
if (operation == "gettimestamp")
{
byte[] id = args[0] as byte[];
TrackedItem item = (TrackedItem)Framework.Helper.Deserialize(Storage.Get(id));
return item.Timestamp;
}
// get the raw serialized bytearray containing all item properties
if (operation == "getserializeddata")
{
byte[] id = args[0] as byte[];
return Storage.Get(id);
}
return false;
}
}
}
@hal0x2328
Copy link
Author

Compiles OK with VS and Neocompiler, fails to compile on NeoRay with the error

编译失败,失败提示:没有生成对应的avm文件编译失败,失败提示:没有生成对应的avm文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment