public async Task <uint256> WaitOfferAsync(OfferData offer, CancellationToken cancellation = default(CancellationToken)) { var scriptPubKey = offer.CreateScriptPubkey(); var chain = GetChain(offer.Initiator.Asset.Chain); return(await WaitConfirmationCoreAsync(chain, scriptPubKey, offer.Initiator.Asset.Amount, 0, cancellation)); }
public async Task <uint256> BroadcastOffer(OfferData offerData, bool watch) { var intitator = GetChain(offerData.Initiator.Asset.Chain); Transaction tx = new Transaction(); tx.AddOutput(offerData.CreateOffer()); if (watch) { await intitator.RPCClient.ImportAddressAsync(offerData.CreateScriptPubkey()).ConfigureAwait(false); } return(await FundAndBroadcast(intitator.RPCClient, tx).ConfigureAwait(false)); }
public async Task <uint256> TakeOffer(OfferData offer) { var taker = GetChain(offer.Taker.Asset.Chain); var initiator = GetChain(offer.Initiator.Asset.Chain); var preimage = _Repository.GetPreimage(offer.Hash); if (preimage == null) { throw new InvalidOperationException("Unknown preimage"); } var key = _Repository.GetPrivateKey(offer.Taker.PubKey); if (key == null) { throw new InvalidOperationException("Unknown pubkey"); } var offerOutpoint = _Repository.GetOffer(offer.CreateScriptPubkey()); if (offerOutpoint == null) { throw new InvalidOperationException("Unknown offer"); } var destination = await initiator.RPCClient.GetNewAddressAsync().ConfigureAwait(false); var tx = new Transaction(); tx.AddInput(new TxIn(offerOutpoint, offer.TakeOffer(new TransactionSignature(key.Sign(uint256.One), SigHash.All), preimage))); tx.AddOutput(new TxOut(offer.Initiator.Asset.Amount, destination)); var fee = (await GetFeeAsync(initiator).ConfigureAwait(false)).GetFee(tx.GetVirtualSize()); tx.Outputs[0].Value -= fee; var offerCoin = new Coin(offerOutpoint, new TxOut(offer.Initiator.Asset.Amount, offer.CreateScriptPubkey())).ToScriptCoin(offer.CreateRedeemScript()); var sig = tx.Inputs.AsIndexedInputs().First().Sign(key, offerCoin, SigHash.All); tx.Inputs[0].ScriptSig = offer.TakeOffer(sig, preimage); await initiator.RPCClient.SendRawTransactionAsync(tx).ConfigureAwait(false); return(tx.GetHash()); }
public Task <uint256> WaitOfferConfirmationAsync(OfferData offer, CancellationToken cancellation = default(CancellationToken)) { return(WaitConfirmationCoreAsync(GetChain(offer.Initiator.Asset.Chain), offer.CreateScriptPubkey(), offer.Initiator.Asset.Amount, 1, cancellation)); }