public void ConstructorAcceptsRelativePath() { string tmpDir = System.IO.Path.GetTempPath(); string dirName = $"defaultstore_{Guid.NewGuid()}"; string cwd = Directory.GetCurrentDirectory(); IStore store; try { Directory.SetCurrentDirectory(tmpDir); store = new DefaultStore(dirName); store.PutTransaction(Fx.Transaction1); } finally { Directory.SetCurrentDirectory(cwd); } // If CWD is changed after DefaultStore instance was created // the instance should work as it had been. store.PutTransaction(Fx.Transaction2); // The following `identicalStore' instance should be identical to // the `store' instance above, i.e., views the same data. var identicalStore = new DefaultStore(Path.Combine(tmpDir, dirName)); Assert.Equal( Fx.Transaction1, identicalStore.GetTransaction <DumbAction>(Fx.Transaction1.Id) ); Assert.Equal( Fx.Transaction2, identicalStore.GetTransaction <DumbAction>(Fx.Transaction2.Id) ); }
public IEnumerator CoMiner() { while (true) { var txs = new HashSet <Transaction <PolymorphicAction <ActionBase> > >(); var task = Task.Run(async() => { var block = await _blocks.MineBlock(Address); if (_swarm?.Running ?? false) { _swarm.BroadcastBlocks(new[] { block }); } return(block); }); yield return(new WaitUntil(() => task.IsCompleted)); if (!task.IsCanceled && !task.IsFaulted) { var block = task.Result; Debug.Log($"created block index: {block.Index}, difficulty: {block.Difficulty}"); } else { var invalidTxs = txs; var retryActions = new HashSet <IImmutableList <PolymorphicAction <ActionBase> > >(); if (task.IsFaulted) { foreach (var ex in task.Exception.InnerExceptions) { if (ex is InvalidTxNonceException invalidTxNonceException) { var invalidNonceTx = _store.GetTransaction <PolymorphicAction <ActionBase> >(invalidTxNonceException.TxId); if (invalidNonceTx.Signer == Address) { Debug.Log($"Tx[{invalidTxNonceException.TxId}] nonce is invalid. Retry it."); retryActions.Add(invalidNonceTx.Actions); } } if (ex is InvalidTxException invalidTxException) { Debug.Log($"Tx[{invalidTxException.TxId}] is invalid. mark to unstage."); invalidTxs.Add( _store.GetTransaction <PolymorphicAction <ActionBase> >(invalidTxException.TxId)); } Debug.LogException(ex); } } _blocks.UnstageTransactions(invalidTxs); foreach (var retryAction in retryActions) { MakeTransaction(retryAction, true); } } } }