Beispiel #1
0
// getFundingParams pulls the relevant transaction information from the json returned by blockchain.info
// To generate a new valid transaction all of the parameters of the TxOut we are
// spending from must be used.
func getFundingParams(rawtx *blockChainInfoTx, vout uint32) (*btcwire.TxOut, *btcwire.OutPoint) {
	blkChnTxOut := rawtx.Outputs[vout]

	hash, err := btcwire.NewShaHashFromStr(rawtx.Hash)
	if err != nil {
		log.Fatal(err)
	}

	// Then convert it to a btcutil amount
	amnt := btcutil.Amount(int64(blkChnTxOut.Value))

	if err != nil {
		log.Fatal(err)
	}

	outpoint := btcwire.NewOutPoint(hash, vout)

	subscript, err := hex.DecodeString(blkChnTxOut.ScriptHex)
	if err != nil {
		log.Fatal(err)
	}

	oldTxOut := btcwire.NewTxOut(int64(amnt), subscript)

	return oldTxOut, outpoint
}
Beispiel #2
0
// createTxOut generates a TxOut can be added to a transaction. Instead of sending
// every coin in the txin to the target address, a fee 10,000 Satoshi is set aside.
// If this fee is left out then, nodes on the network will ignore the transaction,
// since they would otherwise be providing you a service for free.
func createTxOut(inCoin int64, addr btcutil.Address) *btcwire.TxOut {
	// Pay the minimum network fee so that nodes will broadcast the tx.
	outCoin := inCoin - 10000
	// Take the address and generate a PubKeyScript out of it
	script, err := btcscript.PayToAddrScript(addr)
	if err != nil {
		log.Fatal(err)
	}
	txout := btcwire.NewTxOut(outCoin, script)
	return txout
}