Example #1
0
        private Task <ChainCodeInvokeResponse> ChaincodeInvoke(IChaincodeStub stub)
        {
            try
            {
                var chaincode = new Chaincode();
                chaincode.NameSpace = stub.GetChaincodeNameSpace();
                chaincode.Name      = stub.GetChaincodeName();
                chaincode.Version   = stub.GetChaincodeVersion();
                var ass           = _assemblyProvider.GetAssembly(stub.GetChannelId(), stub.GetChaincodeName(), stub.GetChaincodeNameSpace(), stub.GetChaincodeVersion());
                var classfullname = chaincode.NameSpace + "." + chaincode.Name;
                //必须使用 名称空间+类名称
                var type = ass.GetType(classfullname);
                //方法的名称
                MethodInfo method = type.GetMethod("Invoke");
                //必须使用名称空间+类名称
                var obj = ass.CreateInstance(classfullname);
                var rs  = method.Invoke(obj, new object[] { stub });
                if (rs != null)
                {
                    return(Task.FromResult((ChainCodeInvokeResponse)rs));
                }
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(null);
        }
Example #2
0
        private async Task <ChainCodeInvokeResponse> SystemQuery(IChaincodeStub stub)
        {
            switch (stub.GetChaincodeName())
            {
            case ConfigKey.SysCodeLifeChaincode:
                return(new CodeLifeChaincode().Query(stub));

            case ConfigKey.SysNetConfigChaincode:
                return(new NetConfigChaincode().Query(stub));

            case ConfigKey.SysBlockQueryChaincode:
                return(new BlockQueryChaincode().Query(stub));

            default:
                return(null);
            }
        }
Example #3
0
        private Task <ChainCodeInvokeResponse> Submit(IChaincodeStub stub)
        {
            var chaincodeName = stub.GetChaincodeName();

            //系统链码
            if (chaincodeName == ConfigKey.SysBlockQueryChaincode ||
                chaincodeName == ConfigKey.SysCodeLifeChaincode ||
                chaincodeName == ConfigKey.SysNetConfigChaincode)
            {
                switch (stub.GetTxType())
                {
                case TxType.Invoke:
                    return(SystemInvoke(stub));

                case TxType.Query:
                    return(SystemQuery(stub));

                default:
                    return(null);
                }
            }
            //一般交易
            else
            {
                switch (stub.GetTxType())
                {
                case TxType.Invoke:
                    return(ChaincodeInvoke(stub));

                case TxType.Query:
                    return(ChaincodeQuery(stub));

                default:
                    return(null);
                }
            }
        }