当前位置: 首页>>代码示例>>Golang>>正文


Golang btcutil.Tx类代码示例

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


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

示例1: checkTxMalleation

func (a *Anchor) checkTxMalleation(transaction *btcutil.Tx, details *btcjson.BlockDetails) {
	anchorLog.Debug("in checkTxMalleation")
	dirBlockInfos := make([]interfaces.IDirBlockInfo, 0, len(a.dirBlockInfoSlice))
	for _, v := range a.dirBlockInfoSlice {
		// find those already anchored but no call back yet
		if v.GetBTCBlockHeight() == 0 && bytes.Compare(v.GetBTCTxHash().Bytes(), primitives.NewZeroHash().Bytes()) != 0 {
			dirBlockInfos = append(dirBlockInfos, v)
		}
	}
	sort.Sort(util.ByDirBlockInfoTimestamp(dirBlockInfos))
	anchorLog.Debugf("malleated tx candidate count=%d, dirBlockInfo list=%s\n", len(dirBlockInfos), spew.Sdump(dirBlockInfos))
	for _, dirBlockInfo := range dirBlockInfos {
		tx, err := a.wclient.GetRawTransaction(toShaHash(dirBlockInfo.GetBTCTxHash()))
		if err != nil {
			anchorLog.Debugf(err.Error())
			continue
		}
		anchorLog.Debugf("GetRawTransaction=%s, dirBlockInfo=%s\n", spew.Sdump(tx), spew.Sdump(dirBlockInfo))
		// compare OP_RETURN
		if reflect.DeepEqual(transaction.MsgTx().TxOut[0], tx.MsgTx().TxOut[0]) {
			anchorLog.Debugf("Tx Malleated: original.txid=%s, malleated.txid=%s\n", dirBlockInfo.GetBTCTxHash().(*primitives.Hash).BTCString(), transaction.Sha().String())
			a.doSaveDirBlockInfo(transaction, details, dirBlockInfo.(*dbInfo.DirBlockInfo), true)
			break
		}
	}
}
开发者ID:FactomProject,项目名称:factomd,代码行数:26,代码来源:anchor.go

示例2: doSaveDirBlockInfo

func (a *Anchor) doSaveDirBlockInfo(transaction *btcutil.Tx, details *btcjson.BlockDetails, dirBlockInfo *dbInfo.DirBlockInfo, replace bool) {
	if replace {
		dirBlockInfo.BTCTxHash = toHash(transaction.Sha()) // in case of tx being malleated
	}
	dirBlockInfo.BTCTxOffset = int32(details.Index)
	dirBlockInfo.BTCBlockHeight = details.Height
	btcBlockHash, _ := wire.NewShaHashFromStr(details.Hash)
	dirBlockInfo.BTCBlockHash = toHash(btcBlockHash)
	dirBlockInfo.SetTimestamp(primitives.NewTimestampNow())
	a.db.SaveDirBlockInfo(dirBlockInfo)
	anchorLog.Infof("In doSaveDirBlockInfo, dirBlockInfo:%s saved to db\n", spew.Sdump(dirBlockInfo))

	// to make factom / explorer more user friendly, instead of waiting for
	// over 2 hours to know it's anchored, we can create the anchor chain instantly
	// then change it when the btc main chain re-org happens.
	a.saveToAnchorChain(dirBlockInfo)
}
开发者ID:FactomProject,项目名称:factomd,代码行数:17,代码来源:anchor.go

示例3: saveDirBlockInfo

func saveDirBlockInfo(transaction *btcutil.Tx, details *btcjson.BlockDetails) {
	anchorLog.Debug("in saveDirBlockInfo")
	var saved = false
	for _, dirBlockInfo := range dirBlockInfoMap {
		if dirBlockInfo.BTCTxHash != nil &&
			bytes.Compare(dirBlockInfo.BTCTxHash.Bytes(), transaction.Sha().Bytes()) == 0 {
			dirBlockInfo.BTCTxOffset = int32(details.Index)
			dirBlockInfo.BTCBlockHeight = details.Height
			btcBlockHash, _ := wire.NewShaHashFromStr(details.Hash)
			dirBlockInfo.BTCBlockHash = toHash(btcBlockHash)
			dirBlockInfo.BTCConfirmed = true
			db.InsertDirBlockInfo(dirBlockInfo)
			delete(dirBlockInfoMap, dirBlockInfo.DBMerkleRoot.String())
			anchorLog.Infof("In saveDirBlockInfo, dirBlockInfo:%s saved to db\n", spew.Sdump(dirBlockInfo))
			saved = true

			anchorRec := new(AnchorRecord)
			anchorRec.AnchorRecordVer = 1
			anchorRec.DBHeight = dirBlockInfo.DBHeight
			anchorRec.KeyMR = dirBlockInfo.DBMerkleRoot.String()
			_, recordHeight, _ := db.FetchBlockHeightCache()
			anchorRec.RecordHeight = uint32(recordHeight)
			anchorRec.Bitcoin.Address = defaultAddress.String()
			anchorRec.Bitcoin.TXID = transaction.Sha().String()
			anchorRec.Bitcoin.BlockHeight = details.Height
			anchorRec.Bitcoin.BlockHash = details.Hash
			anchorRec.Bitcoin.Offset = int32(details.Index)
			anchorLog.Info("anchor.record saved: " + spew.Sdump(anchorRec))

			//jsonARecord, _ := json.Marshal(anchorRec)
			//anchorLog.Debug("jsonAnchorRecord: ", string(jsonARecord))

			//Submit the anchor record to the anchor chain (entry chain)
			err := submitEntryToAnchorChain(anchorRec)
			if err != nil {
				anchorLog.Error("Error in writing anchor into anchor chain: ", err.Error())
			}

			break
		}
	}
	// should not happen at all?
	if !saved {
		anchorLog.Info("Not saved to db: ")
	}
}
开发者ID:Kalipsol,项目名称:factomd,代码行数:46,代码来源:anchor.go

示例4: saveDirBlockInfo

func saveDirBlockInfo(transaction *btcutil.Tx, details *btcjson.BlockDetails) {
	anchorLog.Debug("in saveDirBlockInfo")
	var saved = false
	for _, dirBlockInfo := range dirBlockInfoMap {
		if bytes.Compare(dirBlockInfo.BTCTxHash.Bytes(), transaction.Sha().Bytes()) == 0 {
			dirBlockInfo.BTCTxOffset = int32(details.Index)
			dirBlockInfo.BTCBlockHeight = details.Height
			btcBlockHash, _ := wire.NewShaHashFromStr(details.Hash)
			dirBlockInfo.BTCBlockHash = toHash(btcBlockHash)
			dirBlockInfo.BTCConfirmed = true
			db.InsertDirBlockInfo(dirBlockInfo)
			delete(dirBlockInfoMap, dirBlockInfo.DBMerkleRoot.String())
			anchorLog.Infof("In saveDirBlockInfo, dirBlockInfo:%s saved to db\n", spew.Sdump(dirBlockInfo))
			saved = true

			anchorRec := new(AnchorRecord)
			anchorRec.AnchorRecordVer = 1
			anchorRec.DBHeight = dirBlockInfo.DBHeight
			anchorRec.KeyMR = dirBlockInfo.DBMerkleRoot.String()
			_, recordHeight, _ := db.FetchBlockHeightCache()
			anchorRec.RecordHeight = uint32(recordHeight)
			anchorRec.Bitcoin.Address = defaultAddress.String()
			anchorRec.Bitcoin.TXID = transaction.Sha().String()
			anchorRec.Bitcoin.BlockHeight = details.Height
			anchorRec.Bitcoin.BlockHash = details.Hash
			anchorRec.Bitcoin.Offset = int32(details.Index)
			anchorLog.Info("anchor.record saved: " + spew.Sdump(anchorRec))

			err := submitEntryToAnchorChain(anchorRec)
			if err != nil {
				anchorLog.Error("Error in writing anchor into anchor chain: ", err.Error())
			}
			break
		}
	}
	// This happends when there's a double spending (for dir block 122 and its btc tx)
	// (see https://www.blocktrail.com/BTC/tx/ac82f4173259494b22f4987f1e18608f38f1ff756fb4a3c637dfb5565aa5e6cf)
	// or tx mutation / malleated
	// In this case, it will end up being re-anchored.
	if !saved {
		anchorLog.Info("Not saved to db: btc.tx=%s\n blockDetails=%s\n", spew.Sdump(transaction), spew.Sdump(details))
	}
}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:43,代码来源:anchor.go

示例5: saveDirBlockInfo

func (a *Anchor) saveDirBlockInfo(transaction *btcutil.Tx, details *btcjson.BlockDetails) {
	anchorLog.Debug("in saveDirBlockInfo")
	var saved = false
	for _, dirBlockInfo := range a.dirBlockInfoSlice {
		if bytes.Compare(dirBlockInfo.GetBTCTxHash().Bytes(), transaction.Sha().Bytes()) == 0 {
			a.doSaveDirBlockInfo(transaction, details, dirBlockInfo.(*dbInfo.DirBlockInfo), false)
			saved = true
			break
		}
	}
	// This happends when there's a double spending or tx malleated(for dir block 122 and its btc tx)
	// Original: https://www.blocktrail.com/BTC/tx/ac82f4173259494b22f4987f1e18608f38f1ff756fb4a3c637dfb5565aa5e6cf
	// malleated: https://www.blocktrail.com/BTC/tx/a9b2d6b5d320c7f0f384a49b167524aca9c412af36ed7b15ca7ea392bccb2538
	// re-anchored: https://www.blocktrail.com/BTC/tx/ac82f4173259494b22f4987f1e18608f38f1ff756fb4a3c637dfb5565aa5e6cf
	// In this case, if tx malleation is detected, then use the malleated tx to replace the original tx;
	// Otherwise, it will end up being re-anchored.
	if !saved {
		anchorLog.Infof("Not saved to db, (maybe btc tx malleated): btc.tx=%s\n blockDetails=%s\n", spew.Sdump(transaction), spew.Sdump(details))
		a.checkTxMalleation(transaction, details)
	}
}
开发者ID:FactomProject,项目名称:factomd,代码行数:21,代码来源:anchor.go

示例6: saveDirBlockInfo

func saveDirBlockInfo(transaction *btcutil.Tx, details *btcjson.BlockDetails) {
	anchorLog.Debug("to save dir block hash to btc.")
	var saved = false
	for _, dirBlockInfo := range dirBlockInfoMap {
		if dirBlockInfo.BTCTxHash != nil &&
			bytes.Compare(dirBlockInfo.BTCTxHash.Bytes(), transaction.Sha().Bytes()) == 0 {
			dirBlockInfo.BTCTxOffset = int32(details.Index)
			dirBlockInfo.BTCBlockHeight = details.Height
			dirBlockInfo.BTCConfirmed = true
			db.InsertDirBlockInfo(dirBlockInfo)
			delete(dirBlockInfoMap, dirBlockInfo.DBMerkleRoot.String())
			anchorLog.Info("In saveDirBlockInfo, dirBlockInfo:%+v saved to db\n", dirBlockInfo)
			saved = true
			break
		}
	}
	// should not happen at all?
	if !saved {
		anchorLog.Info("Not saved to db: ")
	}
}
开发者ID:jakeporter,项目名称:FactomCode,代码行数:21,代码来源:anchor.go


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