public async Task <object> GetManifestFile(UInt160 contractHash) { var contract = contractHash.GetContract(); if (contract == null) { return(Error(ErrorCode.UnknownContract)); } return(contract.Manifest.ToJson()); }
public async Task <object> GetContract(UInt160 contractHash) { var contract = contractHash.GetContract(); if (contract == null) { return(Error(ErrorCode.UnknownContract)); } var model = new ContractModel(contract) { ContractHash = contractHash, }; return(model); }
public async Task <object> DeployContract(string nefPath, string manifestPath = null, bool sendTx = false, UInt160 sender = null) { if (CurrentWallet == null) { return(Error(ErrorCode.WalletNotOpen)); } if (nefPath.IsNull()) { return(Error(ErrorCode.ParameterIsNull, "nefPath is empty.")); } if (manifestPath.IsNull()) { manifestPath = Path.ChangeExtension(nefPath, ".manifest.json"); } // Read nef NefFile nefFile = ReadNefFile(nefPath); // Read manifest ContractManifest manifest = ReadManifestFile(manifestPath); // Basic script checks await CheckBadOpcode(nefFile.Script); // Build script using ScriptBuilder sb = new ScriptBuilder(); sb.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", nefFile.ToArray(), manifest.ToJson().ToString()); //sb.EmitAppCall(NativeContract.Management.Hash, "deploy", nefFile.ToArray(), manifest.ToJson().ToString()); var script = sb.ToArray(); Transaction tx; try { tx = CurrentWallet.MakeTransaction(Helpers.GetDefaultSnapshot(), script, sender); } catch (InvalidOperationException ex) { return(Error(ErrorCode.EngineFault, ex.GetExMessage())); } catch (Exception ex) { if (ex.Message.Contains("Insufficient GAS")) { return(Error(ErrorCode.GasNotEnough)); } throw; } UInt160 hash = SmartContract.Helper.GetContractHash(tx.Sender, nefFile.CheckSum, manifest.Name); var oldContract = hash.GetContract(); if (oldContract != null) { return(Error(ErrorCode.ContractAlreadyExist)); } var result = new DeployResultModel { ContractHash = hash, GasConsumed = new BigDecimal((BigInteger)tx.SystemFee, NativeContract.GAS.Decimals) }; if (sendTx) { var(signSuccess, context) = CurrentWallet.TrySignTx(tx); if (!signSuccess) { return(Error(ErrorCode.SignFail, context.SafeSerialize())); } await tx.Broadcast(); result.TxId = tx.Hash; } return(result); }