本文整理汇总了Golang中github.com/openblockchain/obc-peer/protos.Block.GetTransactions方法的典型用法代码示例。如果您正苦于以下问题:Golang Block.GetTransactions方法的具体用法?Golang Block.GetTransactions怎么用?Golang Block.GetTransactions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openblockchain/obc-peer/protos.Block
的用法示例。
在下文中一共展示了Block.GetTransactions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addIndexDataForPersistence
// Functions for persisting and retrieving index data
func addIndexDataForPersistence(block *protos.Block, blockNumber uint64, blockHash []byte, writeBatch *gorocksdb.WriteBatch) error {
openchainDB := db.GetDBHandle()
cf := openchainDB.IndexesCF
// add blockhash -> blockNumber
indexLogger.Debug("Indexing block number [%d] by hash = [%x]", blockNumber, blockHash)
writeBatch.PutCF(cf, encodeBlockHashKey(blockHash), encodeBlockNumber(blockNumber))
addressToTxIndexesMap := make(map[string][]uint64)
addressToChaincodeIDsMap := make(map[string][]*protos.ChaincodeID)
transactions := block.GetTransactions()
for txIndex, tx := range transactions {
// add TxUUID -> (blockNumber,indexWithinBlock)
writeBatch.PutCF(cf, encodeTxUUIDKey(tx.Uuid), encodeBlockNumTxIndex(blockNumber, uint64(txIndex)))
txExecutingAddress := getTxExecutingAddress(tx)
addressToTxIndexesMap[txExecutingAddress] = append(addressToTxIndexesMap[txExecutingAddress], uint64(txIndex))
switch tx.Type {
case protos.Transaction_CHAINCODE_NEW, protos.Transaction_CHAINCODE_UPDATE:
authroizedAddresses, chaincodeID := getAuthorisedAddresses(tx)
for _, authroizedAddress := range authroizedAddresses {
addressToChaincodeIDsMap[authroizedAddress] = append(addressToChaincodeIDsMap[authroizedAddress], chaincodeID)
}
}
}
for address, txsIndexes := range addressToTxIndexesMap {
writeBatch.PutCF(cf, encodeAddressBlockNumCompositeKey(address, blockNumber), encodeListTxIndexes(txsIndexes))
}
return nil
}
示例2: sendProducerBlockEvent
func sendProducerBlockEvent(block *protos.Block) {
// Remove payload from deploy transactions. This is done to make block
// events more lightweight as the payload for these types of transactions
// can be very large.
blockTransactions := block.GetTransactions()
for _, transaction := range blockTransactions {
if transaction.Type == protos.Transaction_CHAINCODE_NEW {
deploymentSpec := &protos.ChaincodeDeploymentSpec{}
err := proto.Unmarshal(transaction.Payload, deploymentSpec)
if err != nil {
ledgerLogger.Error(fmt.Sprintf("Error unmarshalling deployment transaction for block event: %s", err))
continue
}
deploymentSpec.CodePackage = nil
deploymentSpecBytes, err := proto.Marshal(deploymentSpec)
if err != nil {
ledgerLogger.Error(fmt.Sprintf("Error marshalling deployment transaction for block event: %s", err))
continue
}
transaction.Payload = deploymentSpecBytes
}
}
producer.Send(producer.CreateBlockEvent(block))
}