func extractTxID(txEnvelopBytes []byte) (string, error) { txEnvelope, err := utils.GetEnvelope(txEnvelopBytes) if err != nil { return "", err } txPayload, err := utils.GetPayload(txEnvelope) if err != nil { return "", nil } return txPayload.Header.ChainHeader.TxID, nil }
func extractTransaction(txEnvelopeBytes []byte) (*pb.Transaction, error) { var err error var txEnvelope *common.Envelope var txPayload *common.Payload var tx *pb.Transaction if txEnvelope, err = putil.GetEnvelope(txEnvelopeBytes); err != nil { return nil, err } if txPayload, err = putil.GetPayload(txEnvelope); err != nil { return nil, err } if tx, err = putil.GetTransaction(txPayload.Data); err != nil { return nil, err } return tx, nil }
// Invoke is called to validate the specified block of transactions // This validation system chaincode will check the read-write set validity and at least 1 // correct endorsement. Later we can create more validation system // chaincodes to provide more sophisticated policy processing such as enabling // policy specification to be coded as a transaction of the chaincode and the client // selecting which policy to use for validation using parameter function // @return serialized Block of valid and invalid transactions indentified // Note that Peer calls this function with 2 arguments, where args[0] is the // function name and args[1] is the Envelope func (vscc *ValidatorOneValidSignature) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { // args[0] - function name (not used now) // args[1] - serialized Envelope args := stub.GetArgs() if len(args) < 2 { return nil, errors.New("Incorrect number of arguments") } if args[1] == nil { return nil, errors.New("No block to validate") } logger.Infof("VSCC invoked") // get the envelope... env, err := utils.GetEnvelope(args[1]) if err != nil { logger.Errorf("VSCC error: GetEnvelope failed, err %s", err) return nil, err } // ...and the payload... payl, err := utils.GetPayload(env) if err != nil { logger.Errorf("VSCC error: GetPayload failed, err %s", err) return nil, err } // validate the payload type if common.HeaderType(payl.Header.ChainHeader.Type) != common.HeaderType_ENDORSER_TRANSACTION { logger.Errorf("Only Endorser Transactions are supported, provided type %d", payl.Header.ChainHeader.Type) return nil, fmt.Errorf("Only Endorser Transactions are supported, provided type %d", payl.Header.ChainHeader.Type) } // ...and the transaction... tx, err := utils.GetTransaction(payl.Data) if err != nil { logger.Errorf("VSCC error: GetTransaction failed, err %s", err) return nil, err } // loop through each of the actions within for _, act := range tx.Actions { cap, err := utils.GetChaincodeActionPayload(act.Payload) if err != nil { logger.Errorf("VSCC error: GetChaincodeActionPayload failed, err %s", err) return nil, err } // this is what is being signed prespBytes := cap.Action.ProposalResponsePayload // loop through each of the endorsements for _, endorsement := range cap.Action.Endorsements { // extract the identity of the signer end, err := mspmgmt.GetManagerForChain(payl.Header.ChainHeader.ChainID).DeserializeIdentity(endorsement.Endorser) if err != nil { logger.Errorf("VSCC error: DeserializeIdentity failed, err %s", err) return nil, err } // validate it err = end.Validate() if err != nil { return nil, fmt.Errorf("Invalid endorser identity, err %s", err) } // verify the signature err = end.Verify(append(prespBytes, endorsement.Endorser...), endorsement.Signature) if err != nil { return nil, fmt.Errorf("Invalid signature, err %s", err) } } } logger.Infof("VSCC exists successfully") return nil, nil }