本文整理汇总了Golang中github.com/piotrnar/gocoin/lib/btc.TxPrevOut.Vout方法的典型用法代码示例。如果您正苦于以下问题:Golang TxPrevOut.Vout方法的具体用法?Golang TxPrevOut.Vout怎么用?Golang TxPrevOut.Vout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/piotrnar/gocoin/lib/btc.TxPrevOut
的用法示例。
在下文中一共展示了TxPrevOut.Vout方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: findPendingTxs
// Return txs in mempool that are spending any outputs form the given tx
func findPendingTxs(tx *btc.Tx) (res []BIDX) {
var in btc.TxPrevOut
copy(in.Hash[:], tx.Hash.Hash[:])
for in.Vout = 0; in.Vout < uint32(len(tx.TxOut)); in.Vout++ {
if r, ok := SpentOutputs[in.UIdx()]; ok {
res = append(res, r)
}
}
return res
}
示例2: TxNotifyDel
// This is called while accepting the block (from the chain's thread)
func TxNotifyDel(txid []byte, outs []bool) {
var update_wallet bool
BalanceMutex.Lock()
var uidx btc.TxPrevOut
copy(uidx.Hash[:], txid)
for uidx.Vout = 0; uidx.Vout < uint32(len(outs)); uidx.Vout++ {
if outs[uidx.Vout] {
ii := uidx.UIdx()
if ab, present := CacheUnspentIdx[ii]; present {
adrec := CacheUnspent[ab.Index]
rec := CachedAddrs[adrec.BtcAddr.Hash160]
if rec == nil {
panic("rec not found for " + adrec.BtcAddr.String())
}
rec.Value -= ab.Record.Value
if rec.InWallet {
update_wallet = true
}
for j := range adrec.AllUnspentTx {
if adrec.AllUnspentTx[j] == ab.Record {
//println("found it at index", j)
adrec.AllUnspentTx = append(adrec.AllUnspentTx[:j], adrec.AllUnspentTx[j+1:]...)
break
}
}
delete(CacheUnspentIdx, ii)
}
}
}
if update_wallet {
sync_wallet()
}
BalanceMutex.Unlock()
}
示例3: commitTxs
// This isusually the most time consuming process when applying a new block
func (ch *Chain) commitTxs(bl *btc.Block, changes *BlockChanges) (e error) {
sumblockin := btc.GetBlockReward(changes.Height)
var txoutsum, txinsum, sumblockout uint64
// Add each tx outs from the current block to the temporary pool
blUnsp := make(map[[32]byte][]*btc.TxOut, len(bl.Txs))
for i := range bl.Txs {
outs := make([]*btc.TxOut, len(bl.Txs[i].TxOut))
for j := range bl.Txs[i].TxOut {
bl.Txs[i].TxOut[j].BlockHeight = changes.Height
outs[j] = bl.Txs[i].TxOut[j]
}
blUnsp[bl.Txs[i].Hash.Hash] = outs
}
// create a channnel to receive results from VerifyScript threads:
done := make(chan bool, sys.UseThreads)
for i := range bl.Txs {
txoutsum, txinsum = 0, 0
// Check each tx for a valid input, except from the first one
if i > 0 {
tx_trusted := bl.Trusted
if !tx_trusted && TrustedTxChecker != nil && TrustedTxChecker(bl.Txs[i].Hash) {
tx_trusted = true
}
scripts_ok := true
for j := 0; j < sys.UseThreads; j++ {
done <- true
}
for j := 0; j < len(bl.Txs[i].TxIn); /*&& e==nil*/ j++ {
inp := &bl.Txs[i].TxIn[j].Input
if _, ok := changes.DeledTxs[*inp]; ok {
println("txin", inp.String(), "already spent in this block")
e = errors.New("Input spent more then once in same block")
break
}
tout := ch.PickUnspent(inp)
if tout == nil {
t, ok := blUnsp[inp.Hash]
if !ok {
e = errors.New("Unknown input TxID: " + btc.NewUint256(inp.Hash[:]).String())
break
}
if inp.Vout >= uint32(len(t)) {
println("Vout too big", len(t), inp.String())
e = errors.New("Vout too big")
break
}
if t[inp.Vout] == nil {
println("Vout already spent", inp.String())
e = errors.New("Vout already spent")
break
}
tout = t[inp.Vout]
t[inp.Vout] = nil // and now mark it as spent:
}
if !(<-done) {
println("VerifyScript error 1")
scripts_ok = false
break
}
if tx_trusted {
done <- true
} else {
go func(sig []byte, prv []byte, i int, tx *btc.Tx) {
done <- script.VerifyTxScript(sig, prv, i, tx, bl.BlockTime() >= BIP16SwitchTime)
}(bl.Txs[i].TxIn[j].ScriptSig, tout.Pk_script, j, bl.Txs[i])
}
// Verify Transaction script:
txinsum += tout.Value
changes.DeledTxs[*inp] = tout
}
if scripts_ok {
scripts_ok = <-done
}
for j := 1; j < sys.UseThreads; j++ {
if !(<-done) {
println("VerifyScript error 2")
scripts_ok = false
}
}
if len(done) != 0 {
panic("ASSERT: The channel should be empty gere")
}
if !scripts_ok {
return errors.New("VerifyScripts failed")
//.........这里部分代码省略.........
示例4: load_balance
// load the content of the "balance/" folder
func load_balance(showbalance bool) {
var unknownInputs, multisigInputs int
f, e := os.Open("balance/unspent.txt")
if e != nil {
println(e.Error())
return
}
rd := bufio.NewReader(f)
for {
l, _, e := rd.ReadLine()
if len(l) == 0 && e != nil {
break
}
if l[64] == '-' {
txid := btc.NewUint256FromString(string(l[:64]))
rst := strings.SplitN(string(l[65:]), " ", 2)
vout, _ := strconv.ParseUint(rst[0], 10, 32)
uns := new(btc.TxPrevOut)
copy(uns.Hash[:], txid.Hash[:])
uns.Vout = uint32(vout)
lab := ""
if len(rst) > 1 {
lab = rst[1]
}
str := string(l)
if sti := strings.Index(str, "_StealthC:"); sti != -1 {
c, e := hex.DecodeString(str[sti+10 : sti+10+64])
if e != nil {
fmt.Println("ERROR at stealth", txid.String(), vout, e.Error())
} else {
// add a new key to the wallet
sec := btc.DeriveNextPrivate(first_seed[:], c)
is_stealth[len(priv_keys)] = true
priv_keys = append(priv_keys, sec)
labels = append(labels, lab)
pub_key := btc.PublicFromPrivate(sec, true)
publ_addrs = append(publ_addrs, btc.NewAddrFromPubkey(pub_key, AddrVerPubkey()))
compressed_key = append(compressed_key, true) // stealth keys are always compressed
}
}
if _, ok := loadedTxs[txid.Hash]; !ok {
tf, _ := os.Open("balance/" + txid.String() + ".tx")
if tf != nil {
siz, _ := tf.Seek(0, os.SEEK_END)
tf.Seek(0, os.SEEK_SET)
buf := make([]byte, siz)
tf.Read(buf)
tf.Close()
th := btc.Sha2Sum(buf)
if bytes.Equal(th[:], txid.Hash[:]) {
tx, _ := btc.NewTx(buf)
if tx != nil {
loadedTxs[txid.Hash] = tx
} else {
println("transaction is corrupt:", txid.String())
}
} else {
println("transaction file is corrupt:", txid.String())
os.Exit(1)
}
} else {
println("transaction file not found:", txid.String())
os.Exit(1)
}
}
// Sum up all the balance and check if we have private key for this input
uo := UO(uns)
add_it := true
if !btc.IsP2SH(uo.Pk_script) {
fnd := false
for j := range publ_addrs {
if publ_addrs[j].Owns(uo.Pk_script) {
fnd = true
break
}
}
if !fnd {
if *onlvalid {
add_it = false
}
if showbalance {
unknownInputs++
if *verbose {
ss := uns.String()
ss = ss[:8] + "..." + ss[len(ss)-12:]
fmt.Println(ss, "does not belong to your wallet (cannot sign it)")
}
}
}
} else {
if *onlvalid {
add_it = false
}
//.........这里部分代码省略.........