當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Transaction.String方法代碼示例

本文整理匯總了Golang中github.com/openblockchain/obc-peer/protos.Transaction.String方法的典型用法代碼示例。如果您正苦於以下問題:Golang Transaction.String方法的具體用法?Golang Transaction.String怎麽用?Golang Transaction.String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/openblockchain/obc-peer/protos.Transaction的用法示例。


在下文中一共展示了Transaction.String方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TransactionPreValidation

// TransactionPreValidation verifies that the transaction is
// well formed with the respect to the security layer
// prescriptions (i.e. signature verification).
func (peer *peerImpl) TransactionPreValidation(tx *obc.Transaction) (*obc.Transaction, error) {
	if !peer.isInitialized {
		return nil, utils.ErrNotInitialized
	}

	peer.node.log.Debug("Pre validating [%s].", tx.String())
	peer.node.log.Debug("Tx confdential level [%s].", tx.ConfidentialityLevel.String())

	if tx.Cert != nil && tx.Signature != nil {
		// Verify the transaction
		// 1. Unmarshal cert
		cert, err := utils.DERToX509Certificate(tx.Cert)
		if err != nil {
			peer.node.log.Error("TransactionPreExecution: failed unmarshalling cert [%s] [%s].", err.Error())
			return tx, err
		}
		// TODO: verify cert

		// 3. Marshall tx without signature
		signature := tx.Signature
		tx.Signature = nil
		rawTx, err := proto.Marshal(tx)
		if err != nil {
			peer.node.log.Error("TransactionPreExecution: failed marshaling tx [%s] [%s].", err.Error())
			return tx, err
		}
		tx.Signature = signature

		// 2. Verify signature
		ok, err := peer.node.verify(cert.PublicKey, rawTx, tx.Signature)
		if err != nil {
			peer.node.log.Error("TransactionPreExecution: failed marshaling tx [%s] [%s].", err.Error())
			return tx, err
		}

		if !ok {
			return tx, utils.ErrInvalidTransactionSignature
		}
	} else {
		if tx.Cert == nil {
			return tx, utils.ErrTransactionCertificate
		}

		if tx.Signature == nil {
			return tx, utils.ErrTransactionSignature
		}
	}

	return tx, nil
}
開發者ID:masterDev1985,項目名稱:obc-peer,代碼行數:53,代碼來源:peer_impl.go

示例2: TransactionPreExecution

// TransactionPreValidation verifies that the transaction is
// well formed with the respect to the security layer
// prescriptions (i.e. signature verification). If this is the case,
// the method prepares the transaction to be executed.
func (validator *validatorImpl) TransactionPreExecution(tx *obc.Transaction) (*obc.Transaction, error) {
	if !validator.isInitialized {
		return nil, utils.ErrNotInitialized
	}

	validator.peer.node.log.Debug("Pre executing [%s].", tx.String())
	validator.peer.node.log.Debug("Tx confdential level [%s].", tx.ConfidentialityLevel.String())

	switch tx.ConfidentialityLevel {
	case obc.ConfidentialityLevel_PUBLIC:
		validator.peer.node.log.Debug("Deep cloning.")

		// Nothing to do here. Clone tx.
		clone, err := validator.deepCloneTransaction(tx)
		if err != nil {
			validator.peer.node.log.Error("Failed deep cloning [%s].", err.Error())
			return nil, err
		}

		return clone, nil
	case obc.ConfidentialityLevel_CONFIDENTIAL:
		validator.peer.node.log.Debug("Clone and Decrypt.")

		// Clone the transaction and decrypt it
		newTx, err := validator.decryptTx(tx)
		if err != nil {
			validator.peer.node.log.Error("Failed decrypting [%s].", err.Error())

			return nil, err
		}

		// TODO: Validate confidentiality level. Must be the same on tx and newTx.Spec

		return newTx, nil
	default:
		return nil, utils.ErrInvalidConfidentialityLevel
	}

}
開發者ID:masterDev1985,項目名稱:obc-peer,代碼行數:43,代碼來源:validator_impl.go


注:本文中的github.com/openblockchain/obc-peer/protos.Transaction.String方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。