本文整理汇总了Golang中github.com/conformal/btcscript.ExtractPkScriptAddrs函数的典型用法代码示例。如果您正苦于以下问题:Golang ExtractPkScriptAddrs函数的具体用法?Golang ExtractPkScriptAddrs怎么用?Golang ExtractPkScriptAddrs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ExtractPkScriptAddrs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ExampleExtractPkScriptAddrs
// This example demonstrates extracting information from a standard public key
// script.
func ExampleExtractPkScriptAddrs() {
// Start with a standard pay-to-pubkey-hash script.
scriptHex := "76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac"
script, err := hex.DecodeString(scriptHex)
if err != nil {
fmt.Println(err)
return
}
// Extract and print details from the script.
scriptClass, addresses, reqSigs, err := btcscript.ExtractPkScriptAddrs(
script, &btcnet.MainNetParams)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Script Class:", scriptClass)
fmt.Println("Addresses:", addresses)
fmt.Println("Required Signatures:", reqSigs)
// Output:
// Script Class: pubkeyhash
// Addresses: [12gpXQVcCL2qhTNQgyLVdCFG2Qs2px98nV]
// Required Signatures: 1
}
开发者ID:stoiclabs,项目名称:blockchainr,代码行数:27,代码来源:example_test.go
示例2: createVoutList
// createVoutList returns a slice of JSON objects for the outputs of the passed
// transaction.
func createVoutList(mtx *btcwire.MsgTx, net btcwire.BitcoinNet) ([]btcjson.Vout, error) {
voutList := make([]btcjson.Vout, len(mtx.TxOut))
for i, v := range mtx.TxOut {
voutList[i].N = i
voutList[i].Value = float64(v.Value) / float64(btcutil.SatoshiPerBitcoin)
disbuf, err := btcscript.DisasmString(v.PkScript)
if err != nil {
return nil, btcjson.Error{
Code: btcjson.ErrInternal.Code,
Message: err.Error(),
}
}
voutList[i].ScriptPubKey.Asm = disbuf
voutList[i].ScriptPubKey.Hex = hex.EncodeToString(v.PkScript)
// Ignore the error here since an error means the script
// couldn't parse and there is no additional information about
// it anyways.
scriptClass, addrs, reqSigs, _ := btcscript.ExtractPkScriptAddrs(v.PkScript, net)
voutList[i].ScriptPubKey.Type = scriptClass.String()
voutList[i].ScriptPubKey.ReqSigs = reqSigs
if addrs == nil {
voutList[i].ScriptPubKey.Addresses = nil
} else {
voutList[i].ScriptPubKey.Addresses = make([]string, len(addrs))
for j, addr := range addrs {
voutList[i].ScriptPubKey.Addresses[j] = addr.EncodeAddress()
}
}
}
return voutList, nil
}
开发者ID:Cryptoper,项目名称:btcd,代码行数:37,代码来源:rpcserver.go
示例3: Addresses
// Addresses parses the pubkey script, extracting all addresses for a
// standard script.
func (c Credit) Addresses(net *btcnet.Params) (btcscript.ScriptClass,
[]btcutil.Address, int, error) {
msgTx := c.Tx().MsgTx()
pkScript := msgTx.TxOut[c.OutputIndex].PkScript
return btcscript.ExtractPkScriptAddrs(pkScript, net)
}
开发者ID:kingpro,项目名称:btcwallet,代码行数:9,代码来源:tx.go
示例4: Addresses
// Addresses parses the pubkey script, extracting all addresses for a
// standard script.
func (c *Credit) Addresses(net btcwire.BitcoinNet) (btcscript.ScriptClass,
[]btcutil.Address, int, error) {
msgTx := c.Tx().MsgTx()
pkScript := msgTx.TxOut[c.OutputIndex].PkScript
return btcscript.ExtractPkScriptAddrs(pkScript, net)
}
开发者ID:GeertJohan,项目名称:btcwallet,代码行数:9,代码来源:tx.go
示例5: NotifyForTxOuts
// NotifyForTxOuts iterates through all outputs of a tx, performing any
// necessary notifications for wallets. If a non-nil block is passed,
// additional block information is passed with the notifications.
func (s *rpcServer) NotifyForTxOuts(tx *btcutil.Tx, block *btcutil.Block) {
// Nothing to do if nobody is listening for transaction notifications.
if len(s.ws.txNotifications) == 0 {
return
}
for i, txout := range tx.MsgTx().TxOut {
_, addrs, _, err := btcscript.ExtractPkScriptAddrs(
txout.PkScript, s.server.btcnet)
if err != nil {
continue
}
for _, addr := range addrs {
// Only support pay-to-pubkey-hash right now.
if _, ok := addr.(*btcutil.AddressPubKeyHash); !ok {
continue
}
encodedAddr := addr.EncodeAddress()
if idlist, ok := s.ws.txNotifications[encodedAddr]; ok {
for e := idlist.Front(); e != nil; e = e.Next() {
n := e.Value.(ntfnChan)
ntfn := &btcws.ProcessedTxNtfn{
Receiver: encodedAddr,
TxID: tx.Sha().String(),
TxOutIndex: uint32(i),
Amount: txout.Value,
PkScript: hex.EncodeToString(txout.PkScript),
// TODO(jrick): hardcoding unspent is WRONG and needs
// to be either calculated from other block txs, or dropped.
Spent: false,
}
if block != nil {
blkhash, err := block.Sha()
if err != nil {
rpcsLog.Error("Error getting block sha; dropping Tx notification")
break
}
ntfn.BlockHeight = int32(block.Height())
ntfn.BlockHash = blkhash.String()
ntfn.BlockIndex = tx.Index()
ntfn.BlockTime = block.MsgBlock().Header.Timestamp.Unix()
} else {
ntfn.BlockHeight = -1
ntfn.BlockIndex = -1
}
n <- ntfn
}
}
}
}
}
开发者ID:kawalgrover,项目名称:btcd,代码行数:59,代码来源:rpcwebsocket.go
示例6: ExtractPkScriptAddrs
func ExtractPkScriptAddrs(scriptHex string) {
script, err := hex.DecodeString(scriptHex)
handle(err)
// Extract and print details from the script.
scriptClass, addresses, reqSigs, err := btcscript.ExtractPkScriptAddrs(script, &btcnet.MainNetParams)
handle(err)
fmt.Println("Script Class:", scriptClass)
fmt.Println("Addresses:", addresses)
fmt.Println("Required Signatures:", reqSigs)
}
开发者ID:makevoid,项目名称:bitcoinbook_transifex_build,代码行数:12,代码来源:extract-from-pk-script.go
示例7: ToJSON
// ToJSON returns a slice of objects that may be marshaled as a JSON array
// of JSON objects for a listtransactions RPC reply.
func (c *Credit) ToJSON(account string, chainHeight int32,
net btcwire.BitcoinNet) (btcjson.ListTransactionsResult, error) {
msgTx := c.Tx().MsgTx()
txout := msgTx.TxOut[c.OutputIndex]
var address string
_, addrs, _, _ := btcscript.ExtractPkScriptAddrs(txout.PkScript, net)
if len(addrs) == 1 {
address = addrs[0].EncodeAddress()
}
var category string
switch {
case c.IsCoinbase():
if c.Confirmed(btcchain.CoinbaseMaturity, chainHeight) {
category = "generate"
} else {
category = "immature"
}
default:
category = "receive"
}
result := btcjson.ListTransactionsResult{
Account: account,
Category: category,
Address: address,
Amount: btcutil.Amount(txout.Value).ToUnit(btcutil.AmountBTC),
TxID: c.Tx().Sha().String(),
Time: c.received.Unix(),
TimeReceived: c.received.Unix(),
WalletConflicts: []string{},
}
if c.BlockHeight != -1 {
b, err := c.s.lookupBlock(c.BlockHeight)
if err != nil {
return btcjson.ListTransactionsResult{}, err
}
result.BlockHash = b.Hash.String()
result.BlockIndex = int64(c.Tx().Index())
result.BlockTime = b.Time.Unix()
result.Confirmations = int64(c.Confirmations(chainHeight))
}
return result, nil
}
开发者ID:GeertJohan,项目名称:btcwallet,代码行数:50,代码来源:json.go
示例8: GetAddrs
func GetAddrs(pkScript []byte) (ret []Address, scriptClass btcscript.ScriptClass) {
// Extract the address from the script pub key
scriptClass, addrs, _, _ := btcscript.ExtractPkScriptAddrs(pkScript, btcwire.MainNet)
// Check each output address and if there's an address going to the exodus address
// we add it to tx slice
for _, addr := range addrs {
// Script address returns the public key if it's a multi sig
if scriptClass == btcscript.MultiSigTy {
publicKey := hex.EncodeToString(addr.ScriptAddress())
ret = append(ret, Address{Addr: addr.EncodeAddress(), Raw: []byte(publicKey)})
} else {
ret = append(ret, Address{Addr: addr.EncodeAddress(), Raw: addr.ScriptAddress()})
}
}
return
}
开发者ID:Nevtep,项目名称:mscutil,代码行数:17,代码来源:address.go
示例9: handleDecodeScript
// handleDecodeScript handles decodescript commands.
func handleDecodeScript(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
c := cmd.(*btcjson.DecodeScriptCmd)
// Convert the hex script to bytes.
script, err := hex.DecodeString(c.HexScript)
if err != nil {
return nil, btcjson.Error{
Code: btcjson.ErrInvalidParameter.Code,
Message: fmt.Sprintf("argument must be hexadecimal "+
"string (not %q)", c.HexScript),
}
}
// The disassembled string will contain [error] inline if the script
// doesn't fully parse, so ignore the error here.
disbuf, _ := btcscript.DisasmString(script)
// Get information about the script.
// Ignore the error here since an error means the script couldn't parse
// and there is no additinal information about it anyways.
net := s.server.btcnet
scriptClass, addrs, reqSigs, _ := btcscript.ExtractPkScriptAddrs(script, net)
addresses := make([]string, len(addrs))
for i, addr := range addrs {
addresses[i] = addr.EncodeAddress()
}
// Convert the script itself to a pay-to-script-hash address.
p2sh, err := btcutil.NewAddressScriptHash(script, net)
if err != nil {
return nil, btcjson.Error{
Code: btcjson.ErrInternal.Code,
Message: err.Error(),
}
}
// Generate and return the reply.
reply := btcjson.DecodeScriptResult{
Asm: disbuf,
ReqSigs: reqSigs,
Type: scriptClass.String(),
Addresses: addresses,
P2sh: p2sh.EncodeAddress(),
}
return reply, nil
}
开发者ID:Cryptoper,项目名称:btcd,代码行数:47,代码来源:rpcserver.go
示例10: ToJSON
// ToJSON returns a slice of objects that may be marshaled as a JSON array
// of JSON objects for a listtransactions RPC reply.
func (c *Credit) ToJSON(account string, chainHeight int32,
net *btcnet.Params) (btcjson.ListTransactionsResult, error) {
msgTx := c.Tx().MsgTx()
txout := msgTx.TxOut[c.OutputIndex]
var address string
_, addrs, _, _ := btcscript.ExtractPkScriptAddrs(txout.PkScript, net)
if len(addrs) == 1 {
address = addrs[0].EncodeAddress()
}
result := btcjson.ListTransactionsResult{
Account: account,
Category: c.Category(chainHeight).String(),
Address: address,
Amount: btcutil.Amount(txout.Value).ToUnit(btcutil.AmountBTC),
TxID: c.Tx().Sha().String(),
Time: c.received.Unix(),
TimeReceived: c.received.Unix(),
WalletConflicts: []string{},
}
if c.BlockHeight != -1 {
b, err := c.s.lookupBlock(c.BlockHeight)
if err != nil {
return btcjson.ListTransactionsResult{}, err
}
result.BlockHash = b.Hash.String()
result.BlockIndex = int64(c.Tx().Index())
result.BlockTime = b.Time.Unix()
result.Confirmations = int64(c.Confirmations(chainHeight))
}
return result, nil
}
开发者ID:kingpro,项目名称:btcwallet,代码行数:38,代码来源:json.go
示例11: NtfnRecvTx
// NtfnRecvTx handles the btcws.RecvTxNtfn notification.
func NtfnRecvTx(n btcjson.Cmd) error {
rtx, ok := n.(*btcws.RecvTxNtfn)
if !ok {
return fmt.Errorf("%v handler: unexpected type", n.Method())
}
bs, err := GetCurBlock()
if err != nil {
return fmt.Errorf("%v handler: cannot get current block: %v", n.Method(), err)
}
rawTx, err := hex.DecodeString(rtx.HexTx)
if err != nil {
return fmt.Errorf("%v handler: bad hexstring: %v", n.Method(), err)
}
tx, err := btcutil.NewTxFromBytes(rawTx)
if err != nil {
return fmt.Errorf("%v handler: bad transaction bytes: %v", n.Method(), err)
}
block, txIdx, err := parseBlock(rtx.Block)
if err != nil {
return fmt.Errorf("%v handler: bad block: %v", n.Method(), err)
}
tx.SetIndex(txIdx)
// For transactions originating from this wallet, the sent tx history should
// be recorded before the received history. If wallet created this tx, wait
// for the sent history to finish being recorded before continuing.
//
// TODO(jrick) this is wrong due to tx malleability. Cannot safely use the
// txsha as an identifier.
req := SendTxHistSyncRequest{
txsha: *tx.Sha(),
response: make(chan SendTxHistSyncResponse),
}
SendTxHistSyncChans.access <- req
resp := <-req.response
if resp.ok {
// Wait until send history has been recorded.
<-resp.c
SendTxHistSyncChans.remove <- *tx.Sha()
}
// For every output, find all accounts handling that output address (if any)
// and record the received txout.
for outIdx, txout := range tx.MsgTx().TxOut {
var accounts []*Account
_, addrs, _, _ := btcscript.ExtractPkScriptAddrs(txout.PkScript, cfg.Net())
for _, addr := range addrs {
a, err := AcctMgr.AccountByAddress(addr)
if err != nil {
continue
}
accounts = append(accounts, a)
}
for _, a := range accounts {
txr, err := a.TxStore.InsertTx(tx, block)
if err != nil {
return err
}
cred, err := txr.AddCredit(uint32(outIdx), false)
if err != nil {
return err
}
AcctMgr.ds.ScheduleTxStoreWrite(a)
// Notify frontends of tx. If the tx is unconfirmed, it is always
// notified and the outpoint is marked as notified. If the outpoint
// has already been notified and is now in a block, a txmined notifiction
// should be sent once to let frontends that all previous send/recvs
// for this unconfirmed tx are now confirmed.
op := *cred.OutPoint()
previouslyNotifiedReq := NotifiedRecvTxRequest{
op: op,
response: make(chan NotifiedRecvTxResponse),
}
NotifiedRecvTxChans.access <- previouslyNotifiedReq
if <-previouslyNotifiedReq.response {
NotifiedRecvTxChans.remove <- op
} else {
// Notify frontends of new recv tx and mark as notified.
NotifiedRecvTxChans.add <- op
ltr, err := cred.ToJSON(a.Name(), bs.Height, a.Wallet.Net())
if err != nil {
return err
}
NotifyNewTxDetails(allClients, a.Name(), ltr)
}
// Notify frontends of new account balance.
confirmed := a.CalculateBalance(1)
unconfirmed := a.CalculateBalance(0) - confirmed
NotifyWalletBalance(allClients, a.name, confirmed)
NotifyWalletBalanceUnconfirmed(allClients, a.name, unconfirmed)
}
}
//.........这里部分代码省略.........
开发者ID:GeertJohan,项目名称:btcwallet,代码行数:101,代码来源:ntfns.go
示例12: TestExtractPkScriptAddrs
// TestExtractPkScriptAddrs ensures that extracting the type, addresses, and
// number of required signatures from PkScripts works as intended.
func TestExtractPkScriptAddrs(t *testing.T) {
tests := []struct {
name string
script []byte
addrs []btcutil.Address
reqSigs int
class btcscript.ScriptClass
}{
{
name: "standard p2pk with compressed pubkey (0x02)",
script: decodeHex("2102192d74d0cb94344c9569c2e7790157" +
"3d8d7903c3ebec3a957724895dca52c6b4ac"),
addrs: []btcutil.Address{
newAddressPubKey(decodeHex("02192d74d0cb94344" +
"c9569c2e77901573d8d7903c3ebec3a95772" +
"4895dca52c6b4")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
},
{
name: "standard p2pk with uncompressed pubkey (0x04)",
script: decodeHex("410411db93e1dcdb8a016b49840f8c53bc" +
"1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb" +
"84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643" +
"f656b412a3ac"),
addrs: []btcutil.Address{
newAddressPubKey(decodeHex("0411db93e1dcdb8a0" +
"16b49840f8c53bc1eb68a382e97b1482ecad" +
"7b148a6909a5cb2e0eaddfb84ccf9744464f" +
"82e160bfa9b8b64f9d4c03f999b8643f656b" +
"412a3")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
},
{
name: "standard p2pk with hybrid pubkey (0x06)",
script: decodeHex("4106192d74d0cb94344c9569c2e7790157" +
"3d8d7903c3ebec3a957724895dca52c6b40d45264838" +
"c0bd96852662ce6a847b197376830160c6d2eb5e6a4c" +
"44d33f453eac"),
addrs: []btcutil.Address{
newAddressPubKey(decodeHex("06192d74d0cb94344" +
"c9569c2e77901573d8d7903c3ebec3a95772" +
"4895dca52c6b40d45264838c0bd96852662c" +
"e6a847b197376830160c6d2eb5e6a4c44d33" +
"f453e")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
},
{
name: "standard p2pk with compressed pubkey (0x03)",
script: decodeHex("2103b0bd634234abbb1ba1e986e884185c" +
"61cf43e001f9137f23c2c409273eb16e65ac"),
addrs: []btcutil.Address{
newAddressPubKey(decodeHex("03b0bd634234abbb1" +
"ba1e986e884185c61cf43e001f9137f23c2c" +
"409273eb16e65")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
},
{
name: "2nd standard p2pk with uncompressed pubkey (0x04)",
script: decodeHex("4104b0bd634234abbb1ba1e986e884185c" +
"61cf43e001f9137f23c2c409273eb16e6537a576782e" +
"ba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c" +
"1e0908ef7bac"),
addrs: []btcutil.Address{
newAddressPubKey(decodeHex("04b0bd634234abbb1" +
"ba1e986e884185c61cf43e001f9137f23c2c" +
"409273eb16e6537a576782eba668a7ef8bd3" +
"b3cfb1edb7117ab65129b8a2e681f3c1e090" +
"8ef7b")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
},
{
name: "standard p2pk with hybrid pubkey (0x07)",
script: decodeHex("4107b0bd634234abbb1ba1e986e884185c" +
"61cf43e001f9137f23c2c409273eb16e6537a576782e" +
"ba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c" +
"1e0908ef7bac"),
addrs: []btcutil.Address{
newAddressPubKey(decodeHex("07b0bd634234abbb1" +
"ba1e986e884185c61cf43e001f9137f23c2c" +
"409273eb16e6537a576782eba668a7ef8bd3" +
"b3cfb1edb7117ab65129b8a2e681f3c1e090" +
"8ef7b")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
},
{
name: "standard p2pkh",
//.........这里部分代码省略.........
开发者ID:NSkelsey,项目名称:btcscript,代码行数:101,代码来源:address_test.go
示例13: handleNotification
func (n recvTx) handleNotification() error {
block, txIdx, err := parseBlock(n.block)
if err != nil {
return InvalidNotificationError{err}
}
n.tx.SetIndex(txIdx)
bs, err := GetCurBlock()
if err != nil {
return fmt.Errorf("cannot get current block: %v", err)
}
AcctMgr.Grab()
defer AcctMgr.Release()
// For every output, if it pays to a wallet address, insert the
// transaction into the store (possibly moving it from unconfirmed to
// confirmed), and add a credit record if one does not already exist.
var txr *txstore.TxRecord
txInserted := false
for i, txout := range n.tx.MsgTx().TxOut {
// Errors don't matter here. If addrs is nil, the range below
// does nothing.
_, addrs, _, _ := btcscript.ExtractPkScriptAddrs(txout.PkScript,
activeNet.Params)
for _, addr := range addrs {
a, err := AcctMgr.AccountByAddress(addr)
if err != nil {
continue // try next address, if any
}
if !txInserted {
txr, err = a.TxStore.InsertTx(n.tx, block)
if err != nil {
return err
}
txInserted = true
}
// Insert and notify websocket clients of the credit if it is
// not a duplicate, otherwise, check the next txout if the
// credit has already been inserted.
if txr.HasCredit(i) {
break
}
cred, err := txr.AddCredit(uint32(i), false)
if err != nil {
return err
}
AcctMgr.ds.ScheduleTxStoreWrite(a)
ltr, err := cred.ToJSON(a.Name(), bs.Height, a.Wallet.Net())
if err != nil {
return err
}
server.NotifyNewTxDetails(a.Name(), ltr)
break // check whether next txout is a wallet txout
}
}
server.NotifyBalances()
return nil
}
开发者ID:kingpro,项目名称:btcwallet,代码行数:62,代码来源:rpcclient.go
示例14: handleRescan
// handleRescan implements the rescan command extension for websocket
// connections.
func handleRescan(s *rpcServer, cmd btcjson.Cmd, wallet walletChan) error {
rescanCmd, ok := cmd.(*btcws.RescanCmd)
if !ok {
return btcjson.ErrInternal
}
if len(rescanCmd.Addresses) == 1 {
rpcsLog.Info("Beginning rescan for 1 address.")
} else {
rpcsLog.Infof("Beginning rescan for %v addresses.",
len(rescanCmd.Addresses))
}
minblock := int64(rescanCmd.BeginBlock)
maxblock := int64(rescanCmd.EndBlock)
// FetchHeightRange may not return a complete list of block shas for
// the given range, so fetch range as many times as necessary.
for {
blkshalist, err := s.server.db.FetchHeightRange(minblock,
maxblock)
if err != nil {
return err
}
if len(blkshalist) == 0 {
break
}
for i := range blkshalist {
blk, err := s.server.db.FetchBlockBySha(&blkshalist[i])
if err != nil {
rpcsLog.Errorf("Error looking up block sha: %v",
err)
return err
}
for _, tx := range blk.Transactions() {
var txReply *btcdb.TxListReply
txouts:
for txOutIdx, txout := range tx.MsgTx().TxOut {
_, addrs, _, err := btcscript.ExtractPkScriptAddrs(
txout.PkScript, s.server.btcnet)
if err != nil {
continue txouts
}
for i, addr := range addrs {
encodedAddr := addr.EncodeAddress()
if _, ok := rescanCmd.Addresses[encodedAddr]; ok {
// TODO(jrick): This lookup is expensive and can be avoided
// if the wallet is sent the previous outpoints for all inputs
// of the tx, so any can removed from the utxo set (since
// they are, as of this tx, now spent).
if txReply == nil {
txReplyList, err := s.server.db.FetchTxBySha(tx.Sha())
if err != nil {
rpcsLog.Errorf("Tx Sha %v not found by db.", tx.Sha())
continue txouts
}
for i := range txReplyList {
if txReplyList[i].Height == blk.Height() {
txReply = txReplyList[i]
break
}
}
}
ntfn := &btcws.ProcessedTxNtfn{
Receiver: encodedAddr,
Amount: txout.Value,
TxID: tx.Sha().String(),
TxOutIndex: uint32(txOutIdx),
PkScript: hex.EncodeToString(txout.PkScript),
BlockHash: blkshalist[i].String(),
BlockHeight: int32(blk.Height()),
BlockIndex: tx.Index(),
BlockTime: blk.MsgBlock().Header.Timestamp.Unix(),
Spent: txReply.TxSpent[txOutIdx],
}
mntfn, _ := ntfn.MarshalJSON()
wallet <- mntfn
}
}
}
}
}
if maxblock-minblock > int64(len(blkshalist)) {
minblock += int64(len(blkshalist))
} else {
break
}
}
rpcsLog.Info("Finished rescan")
id := cmd.Id()
response := &btcjson.Reply{
//.........这里部分代码省略.........
开发者ID:Nevtep,项目名称:mastercoind,代码行数:101,代码来源:rpcwebsocket.go
示例15: rescanBlock
// rescanBlock rescans all transactions in a single block. This is a
// helper function for handleRescan.
func rescanBlock(s *rpcServer, cmd *btcws.RescanCmd, c handlerChans, blk *btcutil.Block) {
for _, tx := range blk.Transactions() {
var txReply *btcdb.TxListReply
txouts:
for txOutIdx, txout := range tx.MsgTx().TxOut {
_, addrs, _, err := btcscript.ExtractPkScriptAddrs(
txout.PkScript, s.server.btcnet)
if err != nil {
continue txouts
}
for _, addr := range addrs {
encodedAddr := addr.EncodeAddress()
if _, ok := cmd.Addresses[encodedAddr]; !ok {
continue
}
// TODO(jrick): This lookup is expensive and can be avoided
// if the wallet is sent the previous outpoints for all inputs
// of the tx, so any can removed from the utxo set (since
// they are, as of this tx, now spent).
if txReply == nil {
txReplyList, err := s.server.db.FetchTxBySha(tx.Sha())
if err != nil {
rpcsLog.Errorf("Tx Sha %v not found by db", tx.Sha())
continue txouts
}
for i := range txReplyList {
if txReplyList[i].Height == blk.Height() {
txReply = txReplyList[i]
break
}
}
}
// Sha never errors.
blksha, _ := blk.Sha()
ntfn := &btcws.ProcessedTxNtfn{
Receiver: encodedAddr,
Amount: txout.Value,
TxID: tx.Sha().String(),
TxOutIndex: uint32(txOutIdx),
PkScript: hex.EncodeToString(txout.PkScript),
BlockHash: blksha.String(),
BlockHeight: int32(blk.Height()),
BlockIndex: tx.Index(),
BlockTime: blk.MsgBlock().Header.Timestamp.Unix(),
Spent: txReply.TxSpent[txOutIdx],
}
select {
case <-c.disconnected:
return
default:
c.n <- ntfn
}
}
}
}
}
开发者ID:kawalgrover,项目名称:btcd,代码行数:64,代码来源:rpcwebsocket.go
注:本文中的github.com/conformal/btcscript.ExtractPkScriptAddrs函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论