예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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());
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
 public static Status GetStatus(this FlatClient client) => client.GetStatusAsync().RunAndUnwrap();
예제 #9
0
 public static Peers GetPeers(this FlatClient client) => client.GetPeersAsync().RunAndUnwrap();
예제 #10
0
 public static Channel GetChannel(this FlatClient client, string channelPublicKey) => client.GetChannelAsync(channelPublicKey).RunAndUnwrap();
예제 #11
0
 public static ByteCode GetContractCode(this FlatClient client, string contractPubKey) => client.GetContractCodeAsync(contractPubKey).RunAndUnwrap();
예제 #12
0
 public static UnsignedTx OracleExtend(this FlatClient client, OracleExtendTx tx) => client.CreateDebugOracleExtendAsync(tx).RunAndUnwrap();
예제 #13
0
 public static UnsignedTx OracleAsk(this FlatClient client, OracleQueryTx tx) => client.OracleAskAsync(tx).RunAndUnwrap();
예제 #14
0
 public static UnsignedTx CreateDebugContractCall(this FlatClient client, ContractCallTx tx) => client.CreateDebugContractCallAsync(tx).RunAndUnwrap();
예제 #15
0
 public static UnsignedTx CreateDebugChannelSnapshotSolo(this FlatClient client, ChannelSnapshotSoloTx tx) => client.CreateDebugChannelSnapshotSoloAsync(tx).RunAndUnwrap();
예제 #16
0
 public static OracleQueries GetOracleQueries(this FlatClient client, string oraclePublicKey, string from, ushort?limit, Type?type) => client.GetOracleQueriesAsync(oraclePublicKey, from, limit, type).RunAndUnwrap();
예제 #17
0
 public static OracleQuery GetOracleAnswer(this FlatClient client, string oraclePublicKey, string queryid) => client.GetOracleAnswerAsync(oraclePublicKey, queryid).RunAndUnwrap();
예제 #18
0
 public static CreateContractUnsignedTx CreateDebugContractCreate(this FlatClient client, ContractCreateTx tx) => client.CreateDebugContractCreateAsync(tx).RunAndUnwrap();
예제 #19
0
 public static UnsignedTx OracleRegister(this FlatClient client, OracleRegisterTx tx) => client.CreateDebugOracleRegisterAsync(tx).RunAndUnwrap();
예제 #20
0
 public static UnsignedTx CreateDebugNamePreClaim(this FlatClient client, NamePreclaimTx tx) => client.CreateDebugNamePreClaimAsync(tx).RunAndUnwrap();
예제 #21
0
 public static ContractObject GetContract(this FlatClient client, string contractPubKey) => client.GetContractAsync(contractPubKey).RunAndUnwrap();
예제 #22
0
 public static UnsignedTx CreateDebugNameTransfer(this FlatClient client, NameTransferTx tx) => client.CreateDebugNameTransferAsync(tx).RunAndUnwrap();
예제 #23
0
 public static PoI GetContractPoI(this FlatClient client, string contractPubKey) => client.GetContractPoIAsync(contractPubKey).RunAndUnwrap();
예제 #24
0
 public static UnsignedTx CreateDebugNameUpdate(this FlatClient client, NameUpdateTx tx) => client.CreateDebugNameUpdateAsync(tx).RunAndUnwrap();
예제 #25
0
 public static PeerPubKey GetPeerPublicKey(this FlatClient client) => client.GetPeerPublicKeyAsync().RunAndUnwrap();
예제 #26
0
 public static UnsignedTx CreateDebugOracleQuery(this FlatClient client, OracleQueryTx tx) => client.CreateDebugOracleQueryAsync(tx).RunAndUnwrap();
예제 #27
0
 public static TokenSupply GetTokenSupply(this FlatClient client, ulong height) => client.GetTokenSupplyAsync(height).RunAndUnwrap();
예제 #28
0
 public static UnsignedTx CreateDebugSpend(this FlatClient client, SpendTx tx) => client.CreateDebugSpendAsync(tx).RunAndUnwrap();
 internal ChannelWithdrawTransaction(ILoggerFactory factory, FlatClient client) : base(factory, client)
 {
 }
예제 #30
0
 public static RegisteredOracle GetRegisteredOracle(this FlatClient client, string oraclePublicKey) => client.GetRegisteredOracleAsync(oraclePublicKey).RunAndUnwrap();