public static Transaction CreateGlobalTransfer(SignDelegate2 sign) { CoinReference[] inputs = new CoinReference[] { new CoinReference() { PrevHash = new UInt256(preTxId.Remove(0, 2).HexToBytes().Reverse().ToArray()), PrevIndex = prevIndex //vout n } }.ToArray(); var outputs = new List <TransactionOutput>(); var output1 = new TransactionOutput() { AssetId = UInt256.Parse(assetid), ScriptHash = tansferAddress.ToScriptHash(), Value = tansferValue }; outputs.Add(output1); var tx = new ContractTransaction() { Outputs = outputs.ToArray(), Inputs = inputs, Attributes = new TransactionAttribute[0], Witnesses = new Witness[0] }; return(sign.Invoke(tx)); }
public static Transaction CreateGlobalTransfer(SignDelegate2 sign) { //utxo txid string preTxId = "0x1db3ae57b5f3fda94aa6a81add07a70fc38f0eae9e26f39d7d51183fad0c849f"; UInt256 hash = UInt256.Parse(preTxId); Transaction tx1 = Blockchain.Singleton.GetTransaction(hash); Fixed8 preOutVal = tx1.Outputs[100].Value; Fixed8 currentOutVal = new Fixed8(1 * (long)Math.Pow(10, 8)); if (preOutVal < currentOutVal) { Console.WriteLine("insufficient fund"); return(null); } var inputs = new List <CoinReference> { new CoinReference() { PrevHash = new UInt256(preTxId.Remove(0, 2).HexToBytes().Reverse().ToArray()), PrevIndex = 440 } }.ToArray(); var outputs = new List <TransactionOutput>(); var output1 = new TransactionOutput() { AssetId = UInt256.Parse(assetid), ScriptHash = "AbUAKqt8crJQnhDJWQtFGHT7Pgv9ABnQE6".ToScriptHash(), Value = currentOutVal }; outputs.Add(output1); //if (preOutVal > currentOutVal) //{ // var output2 = new TransactionOutput() // { // AssetId = UInt256.Parse(assetid), // ScriptHash = "AZi4EzuSSp4kiWCUvLZcWo8daymKf53ez6".ToScriptHash(), // Value = preOutVal - currentOutVal // }; // outputs.Add(output2); //} var tx = new ContractTransaction() { Outputs = outputs.ToArray(), Inputs = inputs, Attributes = new TransactionAttribute[0], Witnesses = new Witness[0] }; return(sign.Invoke(tx)); }
public static Transaction CreateMinnerTransaction(SignDelegate2 sign) { // d55ccd8b368aca2402003f39549ad7b75385c226009b3080e0d886959b75b5ce TransactionOutput[] outputs = new TransactionOutput[] { new TransactionOutput { AssetId = Blockchain.GoverningToken.Hash, Value = Fixed8.FromDecimal(444), ScriptHash = currentAddress.ToScriptHash() } }; ulong nonce = GetNonce(); MinerTransaction tx = new MinerTransaction { Nonce = (uint)(nonce % (uint.MaxValue + 1ul)), Attributes = new TransactionAttribute[0], Inputs = new CoinReference[0], Outputs = outputs, Witnesses = new Witness[0] }; return(sign.Invoke(tx)); }