本文整理汇总了Golang中github.com/piotrnar/gocoin/lib/btc.BtcAddr.OutScript方法的典型用法代码示例。如果您正苦于以下问题:Golang BtcAddr.OutScript方法的具体用法?Golang BtcAddr.OutScript怎么用?Golang BtcAddr.OutScript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/piotrnar/gocoin/lib/btc.BtcAddr
的用法示例。
在下文中一共展示了BtcAddr.OutScript方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: list_unspent
func list_unspent(addr string) {
fmt.Println("Checking unspent coins for addr", addr)
defer func() { // in case if ad.OutScript() would panic
if r := recover(); r != nil {
err := r.(error)
fmt.Println("main panic recovered:", err.Error())
}
}()
var ad *btc.BtcAddr
var e error
ad, e = btc.NewAddrFromString(addr)
if e != nil {
println(e.Error())
return
}
sa := ad.StealthAddr
exp_scr := ad.OutScript()
var walk chain.FunctionWalkUnspent
var unsp chain.AllUnspentTx
if sa == nil {
walk = func(db *qdb.DB, k qdb.KeyType, rec *chain.OneWalkRecord) uint32 {
if bytes.Equal(rec.Script(), exp_scr) {
unsp = append(unsp, rec.ToUnspent(ad))
}
return 0
}
} else {
wallet.FetchStealthKeys()
d := wallet.FindStealthSecret(sa)
if d == nil {
fmt.Println("No matching secret found in your wallet/stealth folder")
return
}
walk = func(db *qdb.DB, k qdb.KeyType, rec *chain.OneWalkRecord) uint32 {
if !rec.IsStealthIdx() {
return 0
}
fl, uo := wallet.CheckStealthRec(db, k, rec, ad, d, true)
if uo != nil {
unsp = append(unsp, uo)
}
return fl
}
}
common.BlockChain.Unspent.BrowseUTXO(false, walk)
sort.Sort(unsp)
var sum uint64
for i := range unsp {
if len(unsp) < 200 {
fmt.Println(unsp[i].String())
}
sum += unsp[i].Value
}
fmt.Printf("Total %.8f unspent BTC in %d outputs at address %s\n",
float64(sum)/1e8, len(unsp), ad.String())
}
示例2: list_unspent
func list_unspent(addr string) {
fmt.Println("Checking unspent coins for addr", addr)
defer func() { // in case if ad.OutScript() would panic
if r := recover(); r != nil {
err := r.(error)
fmt.Println("main panic recovered:", err.Error())
}
}()
var ad *btc.BtcAddr
var e error
ad, e = btc.NewAddrFromString(addr)
if e != nil {
println(e.Error())
return
}
sa := ad.StealthAddr
var walk chain.FunctionWalkUnspent
var unsp chain.AllUnspentTx
if sa == nil {
exp_scr := ad.OutScript()
walk = func(tx *chain.QdbRec) {
for idx, rec := range tx.Outs {
if rec != nil && bytes.Equal(rec.PKScr, exp_scr) {
unsp = append(unsp, tx.ToUnspent(uint32(idx), ad))
}
}
}
} else {
var c, spen_exp []byte
var rec, out *chain.QdbTxOut
var h160 [20]byte
wallet.FetchStealthKeys()
d := wallet.FindStealthSecret(sa)
if d == nil {
fmt.Println("No matching secret found in your wallet/stealth folder")
return
}
walk = func(tx *chain.QdbRec) {
for i := 0; i < len(tx.Outs)-1; i++ {
if rec = tx.Outs[i]; rec == nil {
continue
}
if out = tx.Outs[i+1]; out == nil {
continue
}
if !rec.IsStealthIdx() || !out.IsP2KH() || !ad.StealthAddr.CheckNonce(rec.PKScr[3:40]) {
continue
}
c = btc.StealthDH(rec.PKScr[7:40], d)
spen_exp = btc.DeriveNextPublic(sa.SpendKeys[0][:], c)
btc.RimpHash(spen_exp, h160[:])
if bytes.Equal(out.PKScr[3:23], h160[:]) {
uo := new(chain.OneUnspentTx)
uo.TxPrevOut.Hash = tx.TxID
uo.TxPrevOut.Vout = uint32(i + 1)
uo.Value = out.Value
uo.MinedAt = tx.InBlock
uo.BtcAddr = btc.NewAddrFromHash160(h160[:], btc.AddrVerPubkey(common.CFG.Testnet))
uo.FixDestString()
uo.BtcAddr.StealthAddr = sa
uo.BtcAddr.Extra = ad.Extra
uo.StealthC = c
unsp = append(unsp, uo)
}
}
}
}
common.BlockChain.Unspent.BrowseUTXO(false, walk)
sort.Sort(unsp)
var sum uint64
for i := range unsp {
if len(unsp) < 200 {
fmt.Println(unsp[i].String())
}
sum += unsp[i].Value
}
fmt.Printf("Total %.8f unspent BTC in %d outputs at address %s\n",
float64(sum)/1e8, len(unsp), ad.String())
}