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

Golang common.NewHash函数代码示例

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

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



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

示例1: BtcDecode

// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
// This is part of the Message interface implementation.
func (msg *MsgAcknowledgement) BtcDecode(r io.Reader, pver uint32) error {
	//err := readElements(r, &msg.Height, msg.ChainID, &msg.Index, &msg.Type, msg.Affirmation, &msg.SerialHash, &msg.Signature)

	newData, err := ioutil.ReadAll(r)
	if err != nil {
		return fmt.Errorf("MsgAcknowledgement.BtcDecode reader is invalid")
	}

	if len(newData) != 169 {
		return fmt.Errorf("MsgAcknowledgement.BtcDecode reader does not have right length: ", len(newData))
	}

	msg.Height, newData = binary.BigEndian.Uint32(newData[0:4]), newData[4:]

	msg.ChainID = common.NewHash()
	newData, _ = msg.ChainID.UnmarshalBinaryData(newData)

	msg.Index, newData = binary.BigEndian.Uint32(newData[0:4]), newData[4:]

	msg.Type, newData = newData[0], newData[1:]

	msg.Affirmation, _ = NewShaHash(newData[0:32])
	newData = newData[32:]

	copy(msg.SerialHash[:], newData[0:32])
	newData = newData[32:]

	copy(msg.Signature[:], newData[0:63])

	return nil
}
开发者ID:Kalipsol,项目名称:factomd,代码行数:33,代码来源:msgack.go


示例2: sanityCheck

func sanityCheck(hash *common.Hash) (*common.DirBlockInfo, error) {
	dirBlockInfo := dirBlockInfoMap[hash.String()]
	if dirBlockInfo == nil {
		s := fmt.Sprintf("Anchor Error: hash %s does not exist in dirBlockInfoMap.\n", hash.String())
		anchorLog.Error(s)
		return nil, errors.New(s)
	}
	if dirBlockInfo.BTCConfirmed {
		s := fmt.Sprintf("Anchor Warning: hash %s has already been confirmed in btc block chain.\n", hash.String())
		anchorLog.Error(s)
		return nil, errors.New(s)
	}
	if !common.NewHash().IsSameAs(dirBlockInfo.BTCTxHash) {
		s := fmt.Sprintf("Anchor Warning: hash %s has already been anchored but not confirmed. btc tx hash is %s\n", hash.String(), dirBlockInfo.BTCTxHash.String())
		anchorLog.Error(s)
		return nil, errors.New(s)
	}
	if dclient == nil || wclient == nil {
		s := fmt.Sprintf("\n\n$$$ WARNING: rpc clients and/or wallet are not initiated successfully. No anchoring for now.\n")
		anchorLog.Warning(s)
		return nil, errors.New(s)
	}
	if len(balances) == 0 {
		anchorLog.Warning("len(balances) == 0, start rescan UTXO *** ")
		updateUTXO()
	}
	if len(balances) == 0 {
		s := fmt.Sprintf("\n\n$$$ WARNING: No balance in your wallet. No anchoring for now.\n")
		anchorLog.Warning(s)
		return nil, errors.New(s)
	}
	return dirBlockInfo, nil
}
开发者ID:Kalipsol,项目名称:factomd,代码行数:33,代码来源:anchor.go


示例3: atoh

func atoh(a string) (*common.Hash, error) {
	h := common.NewHash()
	p, err := hex.DecodeString(a)
	if err != nil {
		return h, err
	}
	h.SetBytes(p)
	return h, nil
}
开发者ID:6londe,项目名称:FactomCode,代码行数:9,代码来源:api.go


示例4: TestEBlockMarshal

func TestEBlockMarshal(t *testing.T) {
	t.Logf("\n---\nTestEBlockMarshal\n---\n")

	// build an EBlock for testing
	eb := common.NewEBlock()
	eb.Header.ChainID.SetBytes(byteof(0x11))
	eb.Header.BodyMR.SetBytes(byteof(0x22))
	eb.Header.PrevKeyMR.SetBytes(byteof(0x33))
	eb.Header.PrevLedgerKeyMR.SetBytes(byteof(0x44))
	eb.Header.EBSequence = 5
	eb.Header.EBHeight = 6
	eb.Header.EntryCount = 7
	ha := common.NewHash()
	ha.SetBytes(byteof(0xaa))
	hb := common.NewHash()
	hb.SetBytes(byteof(0xbb))
	eb.Body.EBEntries = append(eb.Body.EBEntries, ha)
	eb.AddEndOfMinuteMarker(0xcc)
	eb.Body.EBEntries = append(eb.Body.EBEntries, hb)

	t.Log(eb)
	p, err := eb.MarshalBinary()
	if err != nil {
		t.Error(err)
	}

	eb2 := common.NewEBlock()
	if err := eb2.UnmarshalBinary(p); err != nil {
		t.Error(err)
	}
	t.Log(eb2)
	p2, err := eb2.MarshalBinary()
	if err != nil {
		t.Error(err)
	}

	if string(p) != string(p2) {
		t.Logf("eb1 = %x\n", p)
		t.Logf("eb2 = %x\n", p2)
		t.Fail()
	}
}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:42,代码来源:eblock_test.go


示例5: SignDirectoryBlock

// Sign the directory block
func SignDirectoryBlock() error {
	// Only Servers can write the anchor to Bitcoin network
	if nodeMode == common.SERVER_NODE && dchain.NextDBHeight > 0 {
		// get the previous directory block from db
		dbBlock, _ := db.FetchDBlockByHeight(dchain.NextDBHeight - 1)
		dbHeaderBytes, _ := dbBlock.Header.MarshalBinary()
		identityChainID := common.NewHash() // 0 ID for milestone 1
		sig := serverPrivKey.Sign(dbHeaderBytes)
		achain.NextBlock.AddABEntry(common.NewDBSignatureEntry(identityChainID, sig))
	}
	return nil
}
开发者ID:6londe,项目名称:FactomCode,代码行数:13,代码来源:processor.go


示例6: NewMsgAcknowledgement

// NewMsgAcknowledgement returns a new bitcoin ping message that conforms to the Message
// interface.  See MsgAcknowledgement for details.
func NewMsgAcknowledgement(height uint32, index uint32, affirm *ShaHash, ackType byte) *MsgAcknowledgement {

	if affirm == nil {
		affirm = new(ShaHash)
	}
	return &MsgAcknowledgement{
		Height:      height,
		ChainID:     common.NewHash(), //TODO: get the correct chain id from processor
		Index:       index,
		Affirmation: affirm,
		Type:        ackType,
	}
}
开发者ID:Kalipsol,项目名称:factomd,代码行数:15,代码来源:msgack.go


示例7: FetchEBHashByMR

// FetchEBHashByMR gets an entry by hash from the database.
func (db *LevelDb) FetchEBHashByMR(eBMR *common.Hash) (*common.Hash, error) {
	var key []byte = []byte{byte(TBL_EB_MR)}
	key = append(key, eBMR.Bytes()...)
	db.dbLock.RLock()
	data, err := db.lDb.Get(key, db.ro)
	db.dbLock.RUnlock()
	if err != nil {
		return nil, err
	}

	eBlockHash := common.NewHash()
	_, err = eBlockHash.UnmarshalBinaryData(data)
	if err != nil {
		return nil, err
	}

	return eBlockHash, nil
}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:19,代码来源:eblock.go


示例8: FetchDBHashByMR

// FetchDBHashByMR gets a DBHash by MR from the database.
func (db *LevelDb) FetchDBHashByMR(dBMR *common.Hash) (*common.Hash, error) {
	db.dbLock.Lock()
	defer db.dbLock.Unlock()

	var key []byte = []byte{byte(TBL_DB_MR)}
	key = append(key, dBMR.Bytes()...)
	data, err := db.lDb.Get(key, db.ro)
	if err != nil {
		return nil, err
	}

	dBlockHash := common.NewHash()
	_, err = dBlockHash.UnmarshalBinaryData(data)
	if err != nil {
		return nil, err
	}

	return dBlockHash, nil
}
开发者ID:6londe,项目名称:FactomCode,代码行数:20,代码来源:dblock.go


示例9: FetchDBHashByHeight

// FetchDBHashByHeight gets a dBlockHash from the database.
func (db *LevelDb) FetchDBHashByHeight(dBlockHeight uint32) (*common.Hash, error) {
	var key = []byte{byte(TBL_DB_NUM)}
	var buf bytes.Buffer
	binary.Write(&buf, binary.BigEndian, dBlockHeight)
	key = append(key, buf.Bytes()...)
	db.dbLock.RLock()
	data, err := db.lDb.Get(key, db.ro)
	db.dbLock.RUnlock()
	if err != nil {
		return nil, err
	}

	dBlockHash := common.NewHash()
	_, err = dBlockHash.UnmarshalBinaryData(data)
	if err != nil {
		return nil, err
	}

	return dBlockHash, nil
}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:21,代码来源:dblock.go


示例10: buildIncreaseBalance

func buildIncreaseBalance(msg *wire.MsgFactoidTX) {
	t := msg.Transaction
	for i, ecout := range t.GetECOutputs() {
		ib := common.NewIncreaseBalance()

		pub := new([32]byte)
		copy(pub[:], ecout.GetAddress().Bytes())
		ib.ECPubKey = pub

		th := common.NewHash()
		th.SetBytes(t.GetHash().Bytes())
		ib.TXID = th

		cred := int32(ecout.GetAmount() / uint64(FactoshisPerCredit))
		ib.NumEC = uint64(cred)

		ib.Index = uint64(i)

		ecchain.NextBlock.AddEntry(ib)
	}
}
开发者ID:6londe,项目名称:FactomCode,代码行数:21,代码来源:processor.go


示例11: FetchAllEBlocksByChain

// FetchAllEBlocksByChain gets all of the blocks by chain id
func (db *LevelDb) FetchAllEBlocksByChain(chainID *common.Hash) (eBlocks *[]common.EBlock, err error) {
	db.dbLock.RLock()
	defer db.dbLock.RUnlock()

	var fromkey []byte = []byte{byte(TBL_EB_CHAIN_NUM)} // Table Name (1 bytes)
	fromkey = append(fromkey, chainID.Bytes()...)       // Chain Type (32 bytes)
	var tokey []byte = addOneToByteArray(fromkey)

	eBlockSlice := make([]common.EBlock, 0, 10)

	iter := db.lDb.NewIterator(&util.Range{Start: fromkey, Limit: tokey}, db.ro)

	for iter.Next() {
		eBlockHash := common.NewHash()
		_, err := eBlockHash.UnmarshalBinaryData(iter.Value())
		if err != nil {
			return nil, err
		}

		var key []byte = []byte{byte(TBL_EB)}
		key = append(key, eBlockHash.Bytes()...)
		data, err := db.lDb.Get(key, db.ro)
		if err != nil {
			return nil, err
		}

		eBlock := common.NewEBlock()
		if data != nil {
			_, err := eBlock.UnmarshalBinaryData(data)
			if err != nil {
				return nil, err
			}
			eBlockSlice = append(eBlockSlice, *eBlock)
		}
	}
	iter.Release()
	err = iter.Error()

	return &eBlockSlice, nil
}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:41,代码来源:eblock.go


示例12: FetchHeadMRByChainID

// FetchHeadMRByChainID gets a MR of the highest block from the database.
func (db *LevelDb) FetchHeadMRByChainID(chainID *common.Hash) (blkMR *common.Hash, err error) {
	if chainID == nil {
		return nil, nil
	}

	var key = []byte{byte(TBL_CHAIN_HEAD)}
	key = append(key, chainID.Bytes()...)
	db.dbLock.RLock()
	data, err := db.lDb.Get(key, db.ro)
	db.dbLock.RUnlock()
	if err != nil {
		return nil, err
	}

	blkMR = common.NewHash()
	_, err = blkMR.UnmarshalBinaryData(data)
	if err != nil {
		return nil, err
	}

	return blkMR, nil
}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:23,代码来源:dblock.go


示例13: FetchABlockByHeight

// FetchABlockByHeight gets an admin block by hash from the database.
func (db *LevelDb) FetchABlockByHeight(height uint32) (aBlock *common.AdminBlock, err error) {
	var key = []byte{byte(TBL_AB_NUM)}
	var buf bytes.Buffer
	binary.Write(&buf, binary.BigEndian, height)
	key = append(key, common.ADMIN_CHAINID...)
	key = append(key, buf.Bytes()...)

	var data []byte
	db.dbLock.RLock()
	data, err = db.lDb.Get(key, db.ro)
	db.dbLock.RUnlock()
	if err != nil {
		return nil, err
	}

	aBlockHash := common.NewHash()
	_, err = aBlockHash.UnmarshalBinaryData(data)
	if err != nil {
		return nil, err
	}
	return db.FetchABlockByHash(aBlockHash)
}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:23,代码来源:ablock.go


示例14: FetchECBlockByHeight

// FetchECBlockByHeight gets an Entry Credit block by hash from the database.
func (db *LevelDb) FetchECBlockByHeight(height uint32) (ecBlock *common.ECBlock, err error) {
	var key = []byte{byte(TBL_CB_NUM)}
	var buf bytes.Buffer
	binary.Write(&buf, binary.BigEndian, height)
	key = append(key, common.EC_CHAINID...)
	key = append(key, buf.Bytes()...)
	//fmt.Println("FetchECBlockByHeight: key=", hex.EncodeToString(key))

	var data []byte
	db.dbLock.RLock()
	data, err = db.lDb.Get(key, db.ro)
	db.dbLock.RUnlock()
	if err != nil {
		return nil, err
	}

	ecBlockHash := common.NewHash()
	_, err = ecBlockHash.UnmarshalBinaryData(data)
	if err != nil {
		return nil, err
	}
	//fmt.Println("FetchECBlockByHeight: data=", hex.EncodeToString(data), ", hash=", ecBlockHash)
	return db.FetchECBlockByHash(ecBlockHash)
}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:25,代码来源:ecblock.go


示例15: initProcessor

// Initialize the processor
func initProcessor() {

	wire.Init()

	// init server private key or pub key
	initServerKeys()

	// init mem pools
	fMemPool = new(ftmMemPool)
	fMemPool.init_ftmMemPool()

	// init wire.FChainID
	wire.FChainID = common.NewHash()
	wire.FChainID.SetBytes(common.FACTOID_CHAINID)

	FactoshisPerCredit = 666666 // .001 / .15 * 100000000 (assuming a Factoid is .15 cents, entry credit = .1 cents

	// init Directory Block Chain
	initDChain()

	procLog.Info("Loaded ", dchain.NextDBHeight, " Directory blocks for chain: "+dchain.ChainID.String())

	// init Entry Credit Chain
	initECChain()
	procLog.Info("Loaded ", ecchain.NextBlockHeight, " Entry Credit blocks for chain: "+ecchain.ChainID.String())

	// init Admin Chain
	initAChain()
	procLog.Info("Loaded ", achain.NextBlockHeight, " Admin blocks for chain: "+achain.ChainID.String())

	initFctChain()
	//common.FactoidState.LoadState()
	procLog.Info("Loaded ", fchain.NextBlockHeight, " factoid blocks for chain: "+fchain.ChainID.String())

	//Init anchor for server
	if nodeMode == common.SERVER_NODE {
		anchor.InitAnchor(db, inMsgQueue, serverPrivKey)
	}
	// build the Genesis blocks if the current height is 0
	if dchain.NextDBHeight == 0 && nodeMode == common.SERVER_NODE {
		buildGenesisBlocks()
	} else {
		// To be improved in milestone 2
		SignDirectoryBlock()
	}

	// init process list manager
	initProcessListMgr()

	// init Entry Chains
	initEChains()
	for _, chain := range chainIDMap {
		initEChainFromDB(chain)

		procLog.Info("Loaded ", chain.NextBlockHeight, " blocks for chain: "+chain.ChainID.String())
	}

	// Validate all dir blocks
	err := validateDChain(dchain)
	if err != nil {
		if nodeMode == common.SERVER_NODE {
			panic("Error found in validating directory blocks: " + err.Error())
		} else {
			dchain.IsValidated = false
		}
	}

}
开发者ID:6londe,项目名称:FactomCode,代码行数:69,代码来源:processor.go


示例16: LoadConfigurations

	chainIDMapBackup map[string]*common.EChain //previous block bakcup - ChainIDMap with chainID string([32]byte) as key
	eCreditMapBackup map[string]int32          // backup from previous block - eCreditMap with public key string([32]byte) as key, credit balance as value

	fMemPool *ftmMemPool
	plMgr    *consensus.ProcessListMgr

	//Server Private key and Public key for milestone 1
	serverPrivKey common.PrivateKey
	serverPubKey  common.PublicKey

	FactoshisPerCredit uint64 // .001 / .15 * 100000000 (assuming a Factoid is .15 cents, entry credit = .1 cents

	FactomdUser string
	FactomdPass string

	zeroHash = common.NewHash()
)

var (
	directoryBlockInSeconds int
	dataStorePath           string
	ldbpath                 string
	nodeMode                string
	devNet                  bool
	serverPrivKeyHex        string
	serverIndex             = common.NewServerIndexNumber()
)

// Get the configurations
func LoadConfigurations(cfg *util.FactomdConfig) {
开发者ID:6londe,项目名称:FactomCode,代码行数:30,代码来源:processor.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang common.AdminBlock类代码示例发布时间:2022-05-23
下一篇:
Golang block.IFBlock类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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