public void CreatingContractTypeFromBytesProducesError() { var contract = new Address(Generator.Integer(0, 100), Generator.Integer(0, 100), Generator.Integer(1000, 20000)); var bytes = Abi.EncodeArguments(new[] { contract }); var exception = Assert.Throws <ArgumentOutOfRangeException>(() => { new Endorsement(KeyType.Contract, bytes); }); Assert.Equal("type", exception.ParamName); Assert.StartsWith("Only endorsements representing single Ed25519 or ECDSASecp256K1 keys are supported with this constructor, please use the contract address constructor instead.", exception.Message); }
/// <summary> /// Internal Create Contract Implementation /// </summary> public async Task <TResult> CreateContractImplementationAsync <TResult>(CreateContractParams createParameters, Action <IContext>?configure) where TResult : new() { createParameters = RequireInputParameter.CreateParameters(createParameters); await using var context = CreateChildContext(configure); var gateway = RequireInContext.Gateway(context); var payer = RequireInContext.Payer(context); var signatory = Transactions.GatherSignatories(context, createParameters.Signatory); var transactionId = Transactions.GetOrCreateTransactionID(context); var transactionBody = Transactions.CreateTransactionBody(context, transactionId); transactionBody.ContractCreateInstance = new ContractCreateTransactionBody { FileID = Protobuf.ToFileId(createParameters.File), AdminKey = createParameters.Administrator is null ? null : Protobuf.ToPublicKey(createParameters.Administrator), Gas = createParameters.Gas, InitialBalance = createParameters.InitialBalance, AutoRenewPeriod = Protobuf.ToDuration(createParameters.RenewPeriod), ConstructorParameters = ByteString.CopyFrom(Abi.EncodeArguments(createParameters.Arguments).ToArray()), Memo = context.Memo ?? "" }; var request = await Transactions.SignTransactionAsync(transactionBody, signatory); var precheck = await Transactions.ExecuteSignedRequestWithRetryAsync(context, request, getRequestMethod, getResponseCode); ValidateResult.PreCheck(transactionId, precheck); var receipt = await GetReceiptAsync(context, transactionId); if (receipt.Status != ResponseCodeEnum.Success) { throw new TransactionException($"Unable to create contract, status: {receipt.Status}", Protobuf.FromTransactionId(transactionId), (ResponseCode)receipt.Status); } var result = new TResult(); if (result is CreateContractRecord rec) { var record = await GetTransactionRecordAsync(context, transactionId); Protobuf.FillRecordProperties(record, rec); rec.Contract = Protobuf.FromContractID(receipt.ContractID); } else if (result is CreateContractReceipt rcpt) { Protobuf.FillReceiptProperties(transactionId, receipt, rcpt); rcpt.Contract = Protobuf.FromContractID(receipt.ContractID); } return(result);
internal ContractCreateTransactionBody(Hashgraph.CreateContractParams createParameters) : this() { if (createParameters is null) { throw new ArgumentNullException(nameof(createParameters), "The create parameters are missing. Please check that the argument is not null."); } if (createParameters.File is null) { throw new ArgumentNullException(nameof(createParameters.File), "The File Address containing the contract is missing, it cannot be null."); } FileID = new FileID(createParameters.File); AdminKey = createParameters.Administrator is null ? null : new Key(createParameters.Administrator); Gas = createParameters.Gas; InitialBalance = createParameters.InitialBalance; AutoRenewPeriod = new Duration(createParameters.RenewPeriod); ConstructorParameters = ByteString.CopyFrom(Abi.EncodeArguments(createParameters.Arguments).ToArray()); Memo = createParameters.Memo ?? ""; }
public void CanPackAddressToUint160() { var address = new Address(2, 1, 3); var bytes = Abi.EncodeArguments(new[] { address }); var hex = Hex.FromBytes(bytes)[^ 40..^ 0];