• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang btc.TxPrevOut类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/piotrnar/gocoin/lib/btc.TxPrevOut的典型用法代码示例。如果您正苦于以下问题:Golang TxPrevOut类的具体用法?Golang TxPrevOut怎么用?Golang TxPrevOut使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TxPrevOut类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: del

func (db *unspentDb) del(idx *btc.TxPrevOut) {
	if db.ch.CB.NotifyTx != nil {
		db.ch.CB.NotifyTx(idx, nil)
	}
	key := qdb.KeyType(idx.UIdx())
	db.dbN(int(idx.Hash[31]) % NumberOfUnspentSubDBs).Del(key)
}
开发者ID:vancsj,项目名称:gocoin,代码行数:7,代码来源:qdb_unspent.go


示例2: add

func (db *unspentDb) add(idx *btc.TxPrevOut, Val_Pk *btc.TxOut) {
	v := make([]byte, SCR_OFFS+len(Val_Pk.Pk_script))
	copy(v[0:32], idx.Hash[:])
	binary.LittleEndian.PutUint32(v[32:36], idx.Vout)
	binary.LittleEndian.PutUint64(v[36:44], Val_Pk.Value)
	binary.LittleEndian.PutUint32(v[44:48], Val_Pk.BlockHeight)
	copy(v[SCR_OFFS:], Val_Pk.Pk_script)
	k := qdb.KeyType(idx.UIdx())
	var flgz uint32
	dbN := db.dbN(int(idx.Hash[31]) % NumberOfUnspentSubDBs)
	if stealthIndex(v) {
		if db.ch.CB.NotifyStealthTx != nil {
			db.ch.CB.NotifyStealthTx(dbN, k, NewWalkRecord(v))
		}
		flgz = qdb.YES_CACHE | qdb.YES_BROWSE
	} else {
		if db.ch.CB.NotifyTx != nil {
			db.ch.CB.NotifyTx(idx, Val_Pk)
		}
		if Val_Pk.Value < MinBrowsableOutValue {
			flgz = qdb.NO_CACHE | qdb.NO_BROWSE
		} else if NocacheBlocksBelow == -1 {
			flgz = qdb.NO_CACHE | qdb.NO_BROWSE
		}
	}
	dbN.PutExt(k, v, flgz)
}
开发者ID:vancsj,项目名称:gocoin,代码行数:27,代码来源:qdb_unspent.go


示例3: 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
}
开发者ID:piotrnar,项目名称:gocoin,代码行数:11,代码来源:txpool.go


示例4: TxNotify

// This is called while accepting the block (from the chain's thread)
func TxNotify(idx *btc.TxPrevOut, valpk *btc.TxOut) {
	var update_wallet bool

	BalanceMutex.Lock()

	if valpk != nil {
		// Extract hash160 from pkscript
		adr := btc.NewAddrFromPkScript(valpk.Pk_script, common.Testnet)
		if adr != nil {
			if rec, ok := CachedAddrs[adr.Hash160]; ok {
				rec.Value += valpk.Value
				utxo := new(chain.OneUnspentTx)
				utxo.TxPrevOut = *idx
				utxo.Value = valpk.Value
				utxo.MinedAt = valpk.BlockHeight
				utxo.BtcAddr = CacheUnspent[rec.CacheIndex].BtcAddr
				CacheUnspent[rec.CacheIndex].AllUnspentTx = append(CacheUnspent[rec.CacheIndex].AllUnspentTx, utxo)
				CacheUnspentIdx[idx.UIdx()] = &OneCachedUnspentIdx{Index: rec.CacheIndex, Record: utxo}
				if rec.InWallet {
					update_wallet = true
				}
			}
		}
	} else {
		ii := idx.UIdx()
		if ab, present := CacheUnspentIdx[ii]; present {
			adrec := CacheUnspent[ab.Index]
			//println("removing", idx.String())
			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()
}
开发者ID:vancsj,项目名称:gocoin,代码行数:53,代码来源:balance.go


示例5: get

func (db *unspentDb) get(po *btc.TxPrevOut) (res *btc.TxOut, e error) {
	ind := qdb.KeyType(po.UIdx())
	val := db.dbN(int(po.Hash[31]) % NumberOfUnspentSubDBs).Get(ind)
	if val == nil {
		e = errors.New("Unspent not found")
		return
	}

	if len(val) < SCR_OFFS {
		panic(fmt.Sprint("unspent record too short:", len(val)))
	}

	res = new(btc.TxOut)
	res.Value = binary.LittleEndian.Uint64(val[36:44])
	res.BlockHeight = binary.LittleEndian.Uint32(val[44:48])
	res.Pk_script = make([]byte, len(val)-SCR_OFFS)
	copy(res.Pk_script, val[SCR_OFFS:])
	return
}
开发者ID:vancsj,项目名称:gocoin,代码行数:19,代码来源:qdb_unspent.go


示例6: 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()
}
开发者ID:liudch,项目名称:gocoin,代码行数:37,代码来源:balance.go


示例7: commitTxs


//.........这里部分代码省略.........
					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")
			}
		} else {
			// For coinbase tx we need to check (like satoshi) whether the script size is between 2 and 100 bytes
			// (Previously we made sure in CheckBlock() that this was a coinbase type tx)
			if len(bl.Txs[0].TxIn[0].ScriptSig) < 2 || len(bl.Txs[0].TxIn[0].ScriptSig) > 100 {
				return errors.New(fmt.Sprint("Coinbase script has a wrong length", len(bl.Txs[0].TxIn[0].ScriptSig)))
			}
		}
		sumblockin += txinsum

		for j := range bl.Txs[i].TxOut {
			txoutsum += bl.Txs[i].TxOut[j].Value
			txa := new(btc.TxPrevOut)
			copy(txa.Hash[:], bl.Txs[i].Hash.Hash[:])
			txa.Vout = uint32(j)
			_, spent := changes.DeledTxs[*txa]
			if spent {
				delete(changes.DeledTxs, *txa)
			} else {
				changes.AddedTxs[*txa] = bl.Txs[i].TxOut[j]
			}
		}
		sumblockout += txoutsum

		if e != nil {
			return // If any input fails, do not continue
		}
		if i > 0 && txoutsum > txinsum {
			return errors.New(fmt.Sprintf("More spent (%.8f) than at the input (%.8f) in TX %s",
				float64(txoutsum)/1e8, float64(txinsum)/1e8, bl.Txs[i].Hash.String()))
		}
	}

	if sumblockin < sumblockout {
		return errors.New(fmt.Sprintf("Out:%d > In:%d", sumblockout, sumblockin))
	}

	return nil
}
开发者ID:vancsj,项目名称:gocoin,代码行数:101,代码来源:chain_accept.go


示例8: 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
				}
//.........这里部分代码省略.........
开发者ID:vancsj,项目名称:gocoin,代码行数:101,代码来源:unspent.go



注:本文中的github.com/piotrnar/gocoin/lib/btc.TxPrevOut类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang btc.Uint256类代码示例发布时间:2022-05-28
下一篇:
Golang btc.Tx类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap