diff --git a/.gitignore b/.gitignore index 842e0d0e4f..c85903857e 100644 --- a/.gitignore +++ b/.gitignore @@ -266,12 +266,10 @@ __pycache__/ .vs/ slnx.sqlite -/AElf.Kernel/MerkleTree.cs -/AElf.Kernel/MerkleNode.cs # Generated Protobuf classes *.g.cs -*plugin +grpc_csharp_plugin *Grpc.cs launchSettings.json diff --git a/AElf.Kernel.SmartContract/Infrastructure/IExecutive.cs b/AElf.Kernel.SmartContract/Infrastructure/IExecutive.cs index 3007a42b6d..a114206be2 100644 --- a/AElf.Kernel.SmartContract/Infrastructure/IExecutive.cs +++ b/AElf.Kernel.SmartContract/Infrastructure/IExecutive.cs @@ -17,7 +17,7 @@ public interface IExecutive IExecutive SetStateProviderFactory(IStateProviderFactory stateProviderFactory); void SetDataCache(IStateCache cache); //temporary solution to let data provider access actor's state cache Task Apply(); - ulong GetFee(string methodName); + //ulong GetFee(string methodName); string GetJsonStringOfParameters(string methodName, byte[] paramsBytes); object GetReturnValue(string methodName, byte[] bytes); diff --git a/AElf.Runtime.CSharp.ExecutiveTokenPlugin/AElf.Runtime.CSharp.ExecutiveTokenPlugin.csproj b/AElf.Runtime.CSharp.ExecutiveTokenPlugin/AElf.Runtime.CSharp.ExecutiveTokenPlugin.csproj new file mode 100644 index 0000000000..ede4dcdba5 --- /dev/null +++ b/AElf.Runtime.CSharp.ExecutiveTokenPlugin/AElf.Runtime.CSharp.ExecutiveTokenPlugin.csproj @@ -0,0 +1,12 @@ + + + + netstandard2.0 + + + + + + + + diff --git a/AElf.Runtime.CSharp.ExecutiveTokenPlugin/ExecutiveTokenPluginCSharpRuntimeAElfModule.cs b/AElf.Runtime.CSharp.ExecutiveTokenPlugin/ExecutiveTokenPluginCSharpRuntimeAElfModule.cs new file mode 100644 index 0000000000..1dac67a314 --- /dev/null +++ b/AElf.Runtime.CSharp.ExecutiveTokenPlugin/ExecutiveTokenPluginCSharpRuntimeAElfModule.cs @@ -0,0 +1,12 @@ +using AElf.Common; +using AElf.Kernel.SmartContract; +using AElf.Modularity; +using Volo.Abp.Modularity; + +namespace AElf.Runtime.CSharp.ExecutiveTokenPlugin +{ + [DependsOn(typeof(SmartContractAElfModule))] + public class ExecutiveTokenPluginCSharpRuntimeAElfModule : AElfModule + { + } +} \ No newline at end of file diff --git a/AElf.Runtime.CSharp.ExecutiveTokenPlugin/FeeChargeExecutivePlugin.cs b/AElf.Runtime.CSharp.ExecutiveTokenPlugin/FeeChargeExecutivePlugin.cs new file mode 100644 index 0000000000..17447688b6 --- /dev/null +++ b/AElf.Runtime.CSharp.ExecutiveTokenPlugin/FeeChargeExecutivePlugin.cs @@ -0,0 +1,38 @@ +using System; +using AElf.Kernel; +using AElf.Kernel.SmartContract; +using AElf.Kernel.SmartContract.Infrastructure; +using AElf.Kernel.Token; +using AElf.Kernel.Types.SmartContract; +using AElf.Types.CSharp; +using Google.Protobuf; +using Volo.Abp.DependencyInjection; + +namespace AElf.Runtime.CSharp.ExecutiveTokenPlugin +{ + public class FeeChargeExecutivePlugin : IExecutivePlugin, ITransientDependency + { + public void AfterApply(ISmartContract smartContract, IHostSmartContractBridgeContext context, + Func executeReadOnlyHandler) + { + if (!(smartContract is IFeeChargedContract) || context.TransactionContext.CallDepth > 0) + { + return; + } + + var fee = (ulong) executeReadOnlyHandler(nameof(IFeeChargedContract.GetMethodFee), + + new object[] {context.TransactionContext.Transaction.MethodName}); + + context.TransactionContext.Trace.InlineTransactions.Add(new Transaction() + { + From = context.TransactionContext.Transaction.From, + To = context.GetContractAddressByName( + TokenSmartContractAddressNameProvider.Name), + MethodName = nameof(ITokenContract.ChargeTransactionFees), + Params = ByteString.CopyFrom( + ParamsPacker.Pack(fee)) + }); + } + } +} \ No newline at end of file diff --git a/AElf.Runtime.CSharp/Executive.cs b/AElf.Runtime.CSharp/Executive.cs index e2c83bf180..6b17de689c 100644 --- a/AElf.Runtime.CSharp/Executive.cs +++ b/AElf.Runtime.CSharp/Executive.cs @@ -191,13 +191,14 @@ public async Task ExecuteMainTransaction() CurrentTransactionContext.Trace.Elapsed = (e - s).Ticks; } + /* public ulong GetFee(string methodName) { var handler = _cache.GetHandler(nameof(IFeeChargedContract.GetMethodFee)); var retVal = handler.Execute(ParamsPacker.Pack(methodName)); handler.BytesToReturnType(retVal); return (ulong) handler.BytesToReturnType(retVal); - } + }*/ private object ExecuteReadOnlyHandler(string methodName, params object[] objects) {