public static JObject DecodeCalldata(this FlatClient client, ILogger logger, string encodedValue, string sophiaReturnType) { // decode the result to json SophiaJsonData sophiaJsonData = client.DecodeCallData(encodedValue, sophiaReturnType); return(sophiaJsonData.Data as JObject); }
public static GenericSignedTx WaitForTxMined(this FlatClient client, ILogger logger, string txHash) { long blockHeight = -1; GenericSignedTx minedTx = null; int doneTrials = 1; while (blockHeight == -1 && doneTrials < TestConstants.NUM_TRIALS_DEFAULT) { minedTx = client.GetTransactionByHash(txHash); if (minedTx.BlockHeight > 1) { logger.LogDebug("Mined tx: " + minedTx.TX); blockHeight = minedTx.BlockHeight; } else { logger.LogWarning($"Transaction not mined yet, trying again in 1 second ({doneTrials} of {TestConstants.NUM_TRIALS_DEFAULT})..."); Thread.Sleep(1000); doneTrials++; } } if (blockHeight == -1) { throw new OperationCanceledException($"Transaction {txHash} was not mined after {doneTrials} trials, aborting"); } return(minedTx); }
internal static Account Create(FlatClient client, Generated.Models.Account account, BaseKeyPair keypair) { Account fac = new Account(); fac.Nonce = account?.Nonce ?? 0; fac.Balance = account?.Balance ?? 0; fac.KeyPair = keypair; fac.Client = client; return(fac); }
public static UnsignedTx CreateUnsignedContractCallTx(this FlatClient client, ILogger logger, string callerId, ulong nonce, string calldata, BigInteger?gasPrice, string contractId, BigInteger amount) { ushort abiVersion = Constants.BaseConstants.ABI_VERSION; ulong ttl = 0; ulong gas = 1579000; ContractCallTransaction contractTx = client.CreateContractCallTransaction(abiVersion, calldata, contractId, gas, gasPrice ?? Constants.BaseConstants.MINIMAL_GAS_PRICE, nonce, callerId, ttl); contractTx.Model.Amount = amount; return(contractTx.CreateUnsignedTransaction()); }
public static PostTxResponse PostTx(this FlatClient client, ILogger logger, Tx signedTx) { PostTxResponse postTxResponse = client.PostTransaction(signedTx); logger.LogInformation("Post tx hash :" + postTxResponse.TXHash); GenericSignedTx txValue = client.WaitForTxMined(logger, postTxResponse.TXHash); logger.LogInformation($"Transaction of type {txValue.TX.GetType().Name} is mined at block {txValue.BlockHash} with height {txValue.BlockHeight}"); return(postTxResponse); }
public static void Init(TestContext context) { IConfiguration cfg = new ConfigurationBuilder().AddJsonFile("appsettings.json", true).AddEnvironmentVariables().Build(); ServiceCollection services = new ServiceCollection(); ILoggerFactory fact = new LoggerFactory(new ILoggerProvider[] { new DebugLoggerProvider() }); Configuration ncfg = new Configuration(fact, cfg); services.AddSingleton(fact); services.AddSingleton(cfg); services.AddSingleton(ncfg); ServiceProvider = services.BuildServiceProvider(); string path = Directory.GetCurrentDirectory(); do { if (!File.Exists(Path.Combine(path, "resources", "keystore.json"))) { int l = path.LastIndexOf(Path.DirectorySeparatorChar); path = l == -1 ? null : path.Substring(0, l); } else { ResourcePath = Path.Combine(path, "resources"); break; } } while (path != null); logger = fact.CreateLogger <BaseTest>(); logger.LogInformation("--------------------------- Using following environment ---------------------------"); logger.LogInformation($"{"baseUrl"}:{ncfg.BaseUrl}"); logger.LogInformation($"{"contractBaseUrl"}:{ncfg.ContractBaseUrl}"); Configuration cf = GetNewConfiguration(); cf.NativeMode = false; cf.Network = Constants.Network.DEVNET; debugClient = new FlatClient(cf); cf = GetNewConfiguration(); cf.NativeMode = true; cf.Network = Constants.Network.DEVNET; nativeClient = new FlatClient(cf); baseKeyPair = new BaseKeyPair(TestConstants.BENEFICIARY_PRIVATE_KEY); fluentClient = new Client(cf); }
internal static async Task <Account> CreateAsync(FlatClient client, BaseKeyPair keypair, CancellationToken token = default(CancellationToken)) { Account fac = new Account(); Generated.Models.Account ac = null; try { ac = await client.GetAccountAsync(keypair.PublicKey, token).ConfigureAwait(false); } catch (ApiException <Error> e) { if (!e.Result.Reason.ToLowerInvariant().Contains("not found")) { throw; } } fac.Nonce = ac?.Nonce ?? 0; fac.Balance = ac?.Balance ?? 0; fac.KeyPair = keypair; fac.Client = client; return(fac); }
public static Status GetStatus(this FlatClient client) => client.GetStatusAsync().RunAndUnwrap();
public static Peers GetPeers(this FlatClient client) => client.GetPeersAsync().RunAndUnwrap();
public static Channel GetChannel(this FlatClient client, string channelPublicKey) => client.GetChannelAsync(channelPublicKey).RunAndUnwrap();
public static ByteCode GetContractCode(this FlatClient client, string contractPubKey) => client.GetContractCodeAsync(contractPubKey).RunAndUnwrap();
public static UnsignedTx OracleExtend(this FlatClient client, OracleExtendTx tx) => client.CreateDebugOracleExtendAsync(tx).RunAndUnwrap();
public static UnsignedTx OracleAsk(this FlatClient client, OracleQueryTx tx) => client.OracleAskAsync(tx).RunAndUnwrap();
public static UnsignedTx CreateDebugContractCall(this FlatClient client, ContractCallTx tx) => client.CreateDebugContractCallAsync(tx).RunAndUnwrap();
public static UnsignedTx CreateDebugChannelSnapshotSolo(this FlatClient client, ChannelSnapshotSoloTx tx) => client.CreateDebugChannelSnapshotSoloAsync(tx).RunAndUnwrap();
public static OracleQueries GetOracleQueries(this FlatClient client, string oraclePublicKey, string from, ushort?limit, Type?type) => client.GetOracleQueriesAsync(oraclePublicKey, from, limit, type).RunAndUnwrap();
public static OracleQuery GetOracleAnswer(this FlatClient client, string oraclePublicKey, string queryid) => client.GetOracleAnswerAsync(oraclePublicKey, queryid).RunAndUnwrap();
public static CreateContractUnsignedTx CreateDebugContractCreate(this FlatClient client, ContractCreateTx tx) => client.CreateDebugContractCreateAsync(tx).RunAndUnwrap();
public static UnsignedTx OracleRegister(this FlatClient client, OracleRegisterTx tx) => client.CreateDebugOracleRegisterAsync(tx).RunAndUnwrap();
public static UnsignedTx CreateDebugNamePreClaim(this FlatClient client, NamePreclaimTx tx) => client.CreateDebugNamePreClaimAsync(tx).RunAndUnwrap();
public static ContractObject GetContract(this FlatClient client, string contractPubKey) => client.GetContractAsync(contractPubKey).RunAndUnwrap();
public static UnsignedTx CreateDebugNameTransfer(this FlatClient client, NameTransferTx tx) => client.CreateDebugNameTransferAsync(tx).RunAndUnwrap();
public static PoI GetContractPoI(this FlatClient client, string contractPubKey) => client.GetContractPoIAsync(contractPubKey).RunAndUnwrap();
public static UnsignedTx CreateDebugNameUpdate(this FlatClient client, NameUpdateTx tx) => client.CreateDebugNameUpdateAsync(tx).RunAndUnwrap();
public static PeerPubKey GetPeerPublicKey(this FlatClient client) => client.GetPeerPublicKeyAsync().RunAndUnwrap();
public static UnsignedTx CreateDebugOracleQuery(this FlatClient client, OracleQueryTx tx) => client.CreateDebugOracleQueryAsync(tx).RunAndUnwrap();
public static TokenSupply GetTokenSupply(this FlatClient client, ulong height) => client.GetTokenSupplyAsync(height).RunAndUnwrap();
public static UnsignedTx CreateDebugSpend(this FlatClient client, SpendTx tx) => client.CreateDebugSpendAsync(tx).RunAndUnwrap();
internal ChannelWithdrawTransaction(ILoggerFactory factory, FlatClient client) : base(factory, client) { }
public static RegisteredOracle GetRegisteredOracle(this FlatClient client, string oraclePublicKey) => client.GetRegisteredOracleAsync(oraclePublicKey).RunAndUnwrap();