void tx_fillInputs(byte[] hash, string asset, ThinNeo.Fixed8 count) { var assetid = ""; foreach (var item in Tools.CoinTool.assetUTXO) { if (item.Value == asset || item.Key == asset) { assetid = item.Key; break; } } var address = ThinNeo.Helper.GetAddressFromScriptHash(hash); var thispk = ThinNeo.Helper.GetPublicKeyFromPrivateKey(this.privatekey); var thisaddr = ThinNeo.Helper.GetAddressFromPublicKey(thispk); if (address == thisaddr) { var b = tx_fillThis(assetid, count); if (b == false) { throw new Exception("not have enough coin."); } } }
bool tx_fillThis(string assetid, ThinNeo.Fixed8 count) { if (assetid == "") { throw new Exception("refresh utxo first."); } var pubkey = ThinNeo.Helper.GetPublicKeyFromPrivateKey(this.privatekey); var hash = ThinNeo.Helper.GetScriptHashFromPublicKey(pubkey); foreach (var coins in this.myasset.allcoins) { if (coins.AssetID == assetid) { coins.coins.Sort((a, b) => { return(Math.Sign(a.value - b.value)); }); decimal want = count; decimal inputv = 0; foreach (var c in coins.coins) { Tools.Input input = new Tools.Input(); input.Coin = c; input.From = hash; this.listInput.Items.Add(input); inputv += c.value; if (inputv > want) { break; } } if (inputv < want) { return(false); } else { return(true); } } } return(false); }
public void Load(MyJson.JsonNode_Object json) { this.scripthash = json["scripthash"].AsString(); this.asset = json["asset"].AsString(); if (json["value"] is MyJson.JsonNode_ValueNumber) { decimal v = (decimal)json["value"].AsDouble(); this.value = v; } else if (json["value"] is MyJson.JsonNode_ValueString) { decimal v = decimal.Parse(json["value"].AsString()); this.value = v; } else { throw new Exception("error value type."); } }