private static Register ConvertFieldToContract(CodeGenerator output, Scope scope, Expression expression) { var literal = expression as LiteralExpression; if (literal == null) { throw new CompilerException("nft argument is not a literal value"); } var module = scope.Module.FindModule(literal.value); var abi = module.abi; if (module.Kind == ModuleKind.NFT) { var nftStandard = NFTUtils.GetNFTStandard(); if (!abi.Implements(nftStandard)) { throw new CompilerException($"nft {literal.value} not does implement NFT standard"); } } var reg = Compiler.Instance.AllocRegister(output, expression); var abiBytes = module.abi.ToByteArray(); output.AppendLine(expression, $"LOAD {reg} 0x{Base16.Encode(abiBytes)} // abi"); output.AppendLine(expression, $"PUSH {reg}"); output.AppendLine(expression, $"LOAD {reg} 0x{Base16.Encode(module.script)} // script"); // output.AppendLine(expression, $"PUSH {reg}"); return(reg); }
public override ContractInterface GenerateCode(CodeGenerator output) { var abi = base.GenerateCode(output); var nftStandard = NFTUtils.GetNFTStandard(); // convert ABI parameters var methods = new List <ContractMethod>(); foreach (var method in abi.Methods) { if (nftStandard.HasMethod(method.name)) { var convertedMethod = new ContractMethod(method.name, method.returnType, method.offset, new[] { new ContractParameter("tokenID", VMType.Number) }); methods.Add(convertedMethod); } else { methods.Add(method); } } abi = new ContractInterface(methods, abi.Events); return(abi); }