Ejemplo n.º 1
0
        public static async Task <(JsonRpcError Error, Hash TransactionHash)> TryDeploy(
            bool expectException,
            SolidityContractAttribute contractAttribute,
            IJsonRpcClient rpcClient,
            byte[] bytecode,
            TransactionParams sendParams,
            ReadOnlyMemory <byte> abiEncodedConstructorArgs = default)
        {
            // If we have no code, we shouldn't append our constructor arguments, so we blank ours out.
            if (bytecode == null || bytecode.Length == 0)
            {
                abiEncodedConstructorArgs = default;
            }

            // If constructor args are provided, append to contract bytecode.
            if (!abiEncodedConstructorArgs.IsEmpty)
            {
                sendParams.Data = new byte[bytecode.Length + abiEncodedConstructorArgs.Length];
                Memory <byte> deploymentMem = new Memory <byte>(sendParams.Data);
                bytecode.CopyTo(deploymentMem);
                abiEncodedConstructorArgs.CopyTo(deploymentMem.Slice(bytecode.Length));
            }
            else
            {
                sendParams.Data = bytecode;
            }

            return(await rpcClient.TrySendTransaction(sendParams, expectException));
        }