public static bool Revoke(byte[] claimId, byte[] ontId) { byte[] v = Storage.Get(Storage.CurrentContext, claimId); if (v == null) { ErrorEvent(claimId, " not existed!"); return(false); } ClaimTx c = (ClaimTx)Helper.Deserialize(v); if (c.status != 1) { ErrorEvent(claimId, " invalid status."); return(false); } if (!EqualBytes(c.commiterId, ontId)) { ErrorEvent(ontId, " invalid."); return(false); } c.status = 0; byte[] tx = Helper.Serialize(c); Storage.Put(Storage.CurrentContext, claimId, tx); PushEvent(ontId, " revoke claim: ", claimId); return(true); }
public static object DeserializeStruct(byte[] param) { ClaimTx b2 = (ClaimTx)Helper.Deserialize(param); StorageContext context = Storage.CurrentContext; int value = 100; //&& b2["hello"] == "world" if (b2 != null && (int)b2.claimId == value) { Storage.Put(context, "result", "true"); return(true); } Storage.Put(context, "result", "false"); return((int)b2.claimId); }
public static object TestStruct() { StorageContext context = Storage.CurrentContext; ClaimTx m = new ClaimTx(); m.name = "claimid"; m.claimId = 100; byte[] b = Helper.Serialize(m); Storage.Put(context, "tx", b); byte[] v = Storage.Get(context, "tx"); if (b != null) { return(b); } Storage.Put(context, "result", "false"); return(false); }
// claimId 文件哈希 // commiterId 具体描述 // ownerId ontid public static bool Commit(byte[] claimId, byte[] commiterId, byte[] ownerId) { byte[] v = Storage.Get(Storage.CurrentContext, claimId); if (v != null) { ErrorEvent(claimId, " existed!"); return(false); } ClaimTx c = new ClaimTx(); c.claimId = claimId; c.status = 1; c.commiterId = commiterId; c.ownerId = ownerId; byte[] tx = Helper.Serialize(c); Storage.Put(Storage.CurrentContext, claimId, tx); PushEvent(commiterId, " create new claim: ", claimId); return(true); }