public static bool Execute_old(out Types.Transaction transaction, ContractArgs contractArgs, bool isWitness) { try { var assembly = Assembly.LoadFrom(GetFileName(contractArgs.ContractHash)); var module = assembly.GetModules()[0]; var type = module.GetTypes()[0]; //************************************************** // used for CSharp based contract debugging var matchedTypes = Assembly.GetEntryAssembly() .GetModules()[0] .GetTypes() .Where(t => t.FullName == type.FullName); if (matchedTypes.Any()) { type = matchedTypes.First(); } //************************************************** // used for FSharp based contract debugging //var matchedTypes = Assembly.LoadFile("TestFSharpContracts.dll") // .GetModules()[0] // .GetTypes() // .Where(t => t.FullName == type.FullName); //if (matchedTypes.Any()) //{ // type = matchedTypes.First(); //} var method = type.GetMethod("main"); var args = new object[] { #if CSHARP_CONTRACTS new List <byte>(contractArgs.Message), contractArgs.ContractHash, contractArgs.tryFindUTXOFunc, #else contractArgs.Message, contractArgs.ContractHash, FSharpFunc <Types.Outpoint, FSharpOption <Types.Output> > .FromConverter(t => contractArgs.tryFindUTXOFunc(t)) #endif }; var result = method.Invoke(null, args); #if CSHARP_CONTRACTS var txSkeleton = result as Tuple <IEnumerable <Types.Outpoint>, IEnumerable <Types.Output>, byte[]>; #else var txSkeleton = result as Tuple <FSharpList <Types.Outpoint>, FSharpList <Types.Output>, byte[]>; #endif transaction = txSkeleton == null || txSkeleton.Item2.Count() == 0 ? null : new Types.Transaction( Tests.tx.version, #if CSHARP_CONTRACTS ListModule.OfSeq(txSkeleton.Item1), #else txSkeleton.Item1, #endif ListModule.OfSeq <byte[]>(isWitness ? new byte[][] { contractArgs.Message } : new byte[][] { }), #if CSHARP_CONTRACTS ListModule.OfSeq(txSkeleton.Item2), #else txSkeleton.Item2, #endif FSharpOption <Types.ExtendedContract> .None //TODO: get from txSkeleton.Item3 ); return(true); } catch (Exception e) { BlockChainTrace.Error("Error executing contract", e); } transaction = null; return(false); }
}; //TODO public static bool Execute(out Types.Transaction transaction, ContractArgs contractArgs, bool isWitness) { try { var fileName = HttpServerUtility.UrlTokenEncode(contractArgs.ContractHash); var contractCode = File.ReadAllText(Path.Combine(_OutputPath, Path.ChangeExtension(fileName, ".fs"))); var func = ContractExamples.Execution.compileQuotedContract(contractCode); var result = func.Invoke(new Tuple <byte[], byte[], FSharpFunc <Types.Outpoint, FSharpOption <Types.Output> > >( contractArgs.Message, contractArgs.ContractHash, FSharpFunc <Types.Outpoint, FSharpOption <Types.Output> > .FromConverter(t => contractArgs.tryFindUTXOFunc(t)))); var txSkeleton = result as Tuple <FSharpList <Types.Outpoint>, FSharpList <Types.Output>, byte[]>; transaction = txSkeleton == null || txSkeleton.Item2.Count() == 0 ? null : new Types.Transaction( Tests.tx.version, txSkeleton.Item1, ListModule.OfSeq <byte[]>(isWitness ? new byte[][] { contractArgs.Message } : new byte[][] { }), txSkeleton.Item2, FSharpOption <Types.ExtendedContract> .None //TODO: get from txSkeleton.Item3 ); return(true); } catch (Exception e) { BlockChainTrace.Error("Error executing contract", e); } transaction = null; return(false); }