/// <summary> /// Creates transaction encoder based on Plasma version /// </summary> /// <param name="rootChainVersion">version of plasma. Defaults to RootChainABI.DefaultVersion</param> /// <param name="rootChainAddress">root chain address</param> /// <returns></returns> public static ITransactionEncoder Create(RootChainVersion rootChainVersion, string rootChainAddress) { if (rootChainVersion == RootChainVersion.Default) { rootChainVersion = RootChainABI.DefaultVersion; } if (rootChainVersion == RootChainVersion.Ari) { return(new RawTransactionEncoder()); } else if (rootChainVersion == RootChainVersion.Samrong) { EIP712Domain defaultDomain = new EIP712Domain( "OMG Network", "1", rootChainAddress, "0xfad5c7f626d80f9256ef01929f3beb96e058b8b4b0e3fe52d84f054c0e2a7a83".HexToByteArray()); return(new TypedDataTransactionEncoder(defaultDomain)); } else { throw new NotSupportedException(); } }
/// <summary> /// Creates PlasmaComm object. /// </summary> /// <param name="ethClient">Ethereum jsonRpc client implementation</param> /// <param name="gameCenterContract">game center contract address</param> /// <param name="watcherClient">watcher client</param> /// <param name="childChainClient">child chain client</param> /// <param name="rootChainAddress">root chain address</param> /// <param name="_rootChainVersion">root chain version</param> public PlasmaComm(Nethereum.JsonRpc.Client.IClient ethClient, string gameCenterContract, PlasmaCore.RPC.IClient watcherClient, PlasmaCore.RPC.IClient childChainClient, string rootChainAddress, RootChainVersion _rootChainVersion) { web3 = new Web3(ethClient); bcComm = new BCComm(ethClient, gameCenterContract); plasmaApiService = new PlasmaAPIService(watcherClient, childChainClient); rootChainVersion = _rootChainVersion; if (rootChainAddress == null) { var statusData = plasmaApiService.GetStatus().Result; rootChainAddress = statusData.ContractAddr; } if (rootChainAddress != null) { rootChainContract = new RootChainContract(web3, rootChainAddress, rootChainVersion); } transactionEncoder = TransactionEncoderFactory.Create(rootChainVersion, rootChainAddress); }
/// <summary> /// Creates a new root chain contract /// </summary> /// <param name="web3">web3 interface</param> /// <param name="address">address of this contract (u160)</param> /// <param name="abiVersion">abi version of root chain contract</param> public RootChainContract(Web3 web3, string address, RootChainVersion abiVersion) { this.web3 = web3; abi = RootChainABI.GetRootChainABI(abiVersion); if (abi == null) { throw new ArgumentException("ABI version not found"); } contract = web3.Eth.GetContract(abi, address); }
/// <summary> /// Gets root chain ABI /// </summary> /// <param name="version">requested ABI version</param> /// <returns></returns> public static string GetRootChainABI(RootChainVersion version = RootChainVersion.Default) { if (version == RootChainVersion.Default) { version = DefaultVersion; } if (ABIs.ContainsKey(version)) { return(ABIs[version]); } return(null); }
/// <summary> /// Creates Plasma client options object with root chain access /// </summary> /// <param name="rpcClient">JsonRpc client implementation</param> /// <param name="rootChainAddress">root chain contract address</param> /// <param name="rootChainVersion">root chain version</param> /// <param name="watcherClient">Plasma watcher client</param> /// <param name="childChainClient">Plasma child chain client (optional)</param> public PlasmaClientOptions( Nethereum.JsonRpc.Client.IClient rpcClient, string rootChainAddress, string rootChainVersion, PlasmaCore.RPC.IClient watcherClient, PlasmaCore.RPC.IClient childChainClient = null) : base(rpcClient) { RootChainAddress = rootChainAddress; RootChainVersion = RootChainABI.FromString(rootChainVersion); WatcherClient = watcherClient; ChildChainClient = childChainClient; }
/// <summary> /// Gets standard exit id for given output id /// </summary> /// <param name="web3">web3 interface</param> /// <param name="version">child chain version</param> /// <param name="utxoPosition">UTXO position of the exiting output</param> /// <param name="txBytes">transaction bytes (for Ari version pass null)</param> /// <returns></returns> public async Task <BigInteger> GetStandardExitId(Web3 web3, RootChainVersion version, BigInteger utxoPosition, byte[] txBytes) { var function = GetFunctionGetStandardExitId(); if (version == RootChainVersion.Ari) { return(await function.CallAsync <BigInteger>(utxoPosition)); } else { return(await function.CallAsync <BigInteger>(txBytes, utxoPosition)); } }