Bitcoin Forum
September 22, 2018, 11:52:11 PM *
News: ♦♦ New info! Bitcoin Core users absolutely must upgrade to previously-announced 0.16.3 [Torrent]. All Bitcoin users should temporarily trust confirmations slightly less. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Is this TX possible (Using NBitcoin c#)  (Read 1246 times)
doof
Hero Member
*****
Offline Offline

Activity: 765
Merit: 501


View Profile WWW
July 06, 2016, 12:18:41 AM
 #1

Senario:
Alice has coloured coins (but no bearer tokens)
Bob has bearer tokens

Create a TX to send colour coins from Alice to Carol, with Bob paying the miners fee.

Bitcoin (bearer) change to go back to Bob
Colour coin change to go back to Alice

Here is my attempt:

Raw tx
01000000015c9aed0920c7ea31f867d1c2ead3d01a68b1c37929adfe54f363f340e08cd69400000 0006b483045022100b85cd1009a7d5efe8078c0fe2eb52ebbb6944b92ab655a988bf867dbcdac27 8002206c60f54f027586f6618f357b47c5240f5a24eb9917ba1a513d3e2d31fa700e06012102a34 dd7375accc0201e829eb28d40bafd0add18134b1ea30dff56ef79814e0124ffffffff0300000000 000000000c6a0a4f41010002a846e80700aa0a0000000000001976a914b7c2e22206fcd3eee3cbf a2fd423892355e5114488acaa0a0000000000001976a91467bac1ccbfab92c978a7549971a24f30 97038f9688ac00000000

Code:
protected BE.Models.ITransactionBroadcastResponse Transfer(BitcoinAddress fromAddress, BitcoinAddress toAddress, BitcoinAddress agentAddress, IEnumerable<ICoin> bearer, ICoin colored, AssetMoney assetToSend, AssetMoney autarkyFee, AssetMoney agentFee)
{
try
{
//Apps private key
BitcoinSecret bearerKey = new BitcoinSecret(this.BearerKey);
                BitcoinSecret assetOwnerKey = new BitcoinSecret(this.AssetOwnerKey);

TransactionBuilder txBuilder = new TransactionBuilder();
txBuilder
.AddKeys(bearerKey)
.AddCoins(bearer)
                    .AddKeys(assetOwnerKey)
.AddCoins(colored)
.SendAsset(toAddress, assetToSend)
//.SendAsset(agentAddress, agentFee)
//.SendAsset(AutarkyBitcoinAddress, autarkyFee)
                    .SetChange(AutarkyBitcoinAddress, ChangeType.Uncolored) //was from address
                    .SetChange(fromAddress, ChangeType.Colored)
.SendFees(this.MinersFee);

Transaction tx = txBuilder.BuildTransaction(true);
Boolean ok = txBuilder.Verify(tx);

if (ok == true)
{
#if DEBUG
                    String hex = tx.ToHex();
#endif
String response = NetworkClient.BroadCastTx(tx.ToHex());
return new BE.Models.NodeTransactionResponse() { status = "ok", data = response };
}
else
{
                    //TODO MAKE TX INVALID EXCEPTION
//return new Models.TransactionErrorResponse() { status = "Error", data = "The transaction is invalid" };
throw new Exception();
}
}
catch (Exception ex)
{
//return new Models.TransactionErrorResponse() { status = "Error", data = "The transaction is invalid.  " + ex.Message };
throw ex;
}
}
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!