private static Deed getDeed(string label, byte[] who) { byte[] key = bidkey(label, who); byte[] data = Storage.Get(Storage.CurrentContext, key); Deed deed = new Deed(null, 0); if (data.Length == 0) { return(deed); } int seek = 0; int len = 0; // deed.owner len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; deed.owner = data.Range(seek, len); seek += len; // deed.createOn len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; deed.createOn = data.Range(seek, len).AsBigInteger(); seek += len; // deed.value len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; deed.value = data.Range(seek, len).AsBigInteger(); seek += len; return(deed); }
public static Boolean newBid(string label, byte[] who, BigInteger value) { if (isAvailable(label) == false) { return(false); } var checkBid = getDeed(label, who); if (checkBid.value != 0) { // already bid return(false); } Deed newDeed = new Deed(who, value); saveDeed(label, who, newDeed); Runtime.Notify(new Object[] { "create new bid", label }); return(true); }
private static void saveDeed(string label, byte[] who, Deed deed) { byte[] key = bidkey(label, who); byte[] doublezero = new byte[] { 0, 0 }; // deed.owner var data = deed.owner; var datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); var value = datalen.Concat(data); // deed.createOn data = deed.createOn.AsByteArray(); datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); value = datalen.Concat(data); // deed.value data = deed.value.AsByteArray(); datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); value = datalen.Concat(data); Runtime.Notify(new Object[] { "save deed", label }); Storage.Put(Storage.CurrentContext, key, value); }