I've been working with Nicolas to help get this done, but I think hes pretty busy.
I've got code to Issue colour coins from Bob to Alice. However, I cant get a transfer of the assets.
Bob -> 20 Gold -> Alice
Alice -> 10 Gold -> Doof
This is where Im getting stuck. After the tx builder I get a valid tx hash. However if I broad cast nothing happens. Some code snippets, sorry for the commenting, been trying lots of different approaches.
Ill pay once working code is submitted. Im using blockr or coinprism as a repo to get the txs. Happy to hard code a tx hash and script sig to pay the bounty, as long as I can retrieve new ones in the future from my repo.
Notes:
INetwork just calls my bitcoin-core client
Some test keys
const String BobAddress = "mxSimcis5yCPkBaFZ7ZrJ7fsPqLXatxTax";
const String BobAssetAddress = "bX8Qc1nYCZT65cRjcbjg2wyaSjSWhY2gB5p";
const String BobWIFKey = "cMdLBsUCQ92VSRmqfEL4TgJCisWpjVBd8GsP2mAmUZxQ9bh5E7CN";
const String AliceAddress = "muJjaSHk99LGMnaFduU9b3pWHdT1ZRPASF";
const String AliceAssetAddress = "bX5Gcpc75cdDxE2jcgXaLEuj5dEdBUdnpDu";
const String AlicePrivateWIFKey = "cPKW4EsFiPeczwHeSCgo4GTzm4T291Xb6sLGi1HoroXkiqGcGgsH";
assetId = "oLcV5F6R59zbChoTBQ962Har24tAnhbtHo";
public string Transfer(String fromAddress, Int64 amount, String toAddress, String assetId, INetwork network)
{
//Get bitcoin balance, 0.0006 is required
Decimal fundingBalance = 0;
const Decimal BITCOIN_TRANSACTION_FEE = 0.00006M;
NBitcoin.BitcoinAddress bitcoinToAddress = new BitcoinAddress(toAddress);
NBitcoin.BitcoinAddress bitcoinFromAddress = new BitcoinAddress(fromAddress);
//UTXOS
EP.Repository.ColourCoinTransaction.CoinPrism txRepo = new Repository.ColourCoinTransaction.CoinPrism(true);
var ccutoxs = txRepo.GetTransactions(fromAddress);
var utxos = txRepo.Get(fromAddress).Where(ux => ux.value > 10000).ToList();
//hard coded, worked but didn't send assets
//transaction_hash
//var coin = new Coin(fromTxHash: new uint256("f131c91b3ce35f83258a3db54f5547daecc2a61142f598a39a8491ed2844eb28"),
// fromOutputIndex: 0,
// amount: Money.Satoshis(3000), //20000
// scriptPubKey: new Script(Encoders.Hex.DecodeData("76a914b9ad2f3f358c24ec207abf72125790e67301284488ac")));
//var forfees = new Coin(fromTxHash: new uint256("a86a907f36071754ff4fdc4e27de4ec92272f239de5236af5f4806133ac66d0f"),
// fromOutputIndex: 0,
// amount: Money.Satoshis(97322000), //9957600
// scriptPubKey: new Script(Encoders.Hex.DecodeData("76a914b9ad2f3f358c24ec207abf72125790e67301284488ac")));
var coin = new Coin(fromTxHash: new uint256("dc19133d57bf9013d898bd89198069340d8ca99d71f0d5f6c6e142d724a9ba92"),
fromOutputIndex: 0,
amount: Money.Satoshis(199867600), //20000
scriptPubKey: new Script(Encoders.Hex.DecodeData("76a914b9ad2f3f358c24ec207abf72125790e67301284488ac")));
var forfees = new Coin(fromTxHash: new uint256("302290290074826991bb936c157ef1e5be2882e975154d31b985ae8a26dd3161"),
fromOutputIndex: 2,
amount: Money.Satoshis(20000), //9957600
scriptPubKey: new Script(Encoders.Hex.DecodeData("76a914b9ad2f3f358c24ec207abf72125790e67301284488ac")));
//var coin = new Coin(fromTxHash: new uint256(utxos[0].transaction_hash),
// fromOutputIndex: utxos[0].output_index,
// amount: Money.Satoshis(60000), //20000
// scriptPubKey: new Script(Encoders.Hex.DecodeData(utxos[0].script_hex)));
//var forfees = new Coin(fromTxHash: new uint256(utxos[1].transaction_hash),
// fromOutputIndex: utxos[1].output_index,
// amount: Money.Satoshis(60000), //20000
// scriptPubKey: new Script(Encoders.Hex.DecodeData(utxos[1].script_hex)));
BitcoinAssetId assetIdx = new BitcoinAssetId(assetId, Network.TestNet);
var alice = NBitcoin.BitcoinAddress.Create(toAddress, NBitcoin.Network.TestNet);
ulong u = Convert.ToUInt64(amount);
ColoredCoin colored = coin.ToColoredCoin(assetIdx, u);
//var satoshi = Key.Parse(, Network.TestNet);
string aliceWIF = "cPKW4EsFiPeczwHeSCgo4GTzm4T291Xb6sLGi1HoroXkiqGcGgsH";
var satoshi = Key.Parse(aliceWIF, Network.TestNet); ;
var txBuilder = new TransactionBuilder();
var tx = txBuilder
.AddKeys(_key.PrivateKey)
//.AddCoins(forfees, colored)
.AddCoins(forfees)
.AddCoins(colored)
.SendAsset(alice, new AssetMoney(assetIdx, u))
//.SendAsset(satoshi.PubKey, new NBitcoin.OpenAsset.AssetMoney(assetIdx, u))
.SetChange(bitcoinFromAddress)
.SendFees(Money.Coins(0.001m))
.BuildTransaction(true);
network.Submit(tx);
return "ok";
}