示例#1
0
void WalletLegacy::initAndGenerateOrRecover
	(
		const std::string& password, 
		const Crypto::SecretKey& recovery_key,
		const Crypto::SecretKey& secondary_key,
		bool is_recovery, 
		bool is_copy, 
		bool is_deterministic
	) 
{

  {
    std::unique_lock<std::mutex> stateLock(m_cacheMutex);

    if (m_state != NOT_INITIALIZED) {
      throw std::system_error(make_error_code(error::ALREADY_INITIALIZED));
    }

    m_account.generate_or_recover(recovery_key, secondary_key, is_recovery, is_copy, is_deterministic);
    m_password = password;

    initSync();
  }

  m_observerManager.notify(&IWalletLegacyObserver::initCompleted, std::error_code());
}
示例#2
0
void WalletLegacy::doLoad(std::istream& source) {
  ContextCounterHolder counterHolder(m_asyncContextCounter);
  try {
    std::unique_lock<std::mutex> lock(m_cacheMutex);
    
    std::string cache;
    WalletLegacySerializer serializer(m_account, m_transactionsCache);
    serializer.deserialize(source, m_password, cache);
      
    initSync();

    try {
      if (!cache.empty()) {
        std::stringstream stream(cache);
        m_transfersSync.load(stream);
      }
    } catch (const std::exception&) {
      // ignore cache loading errors
    }
  } catch (std::system_error& e) {
    runAtomic(m_cacheMutex, [this] () {this->m_state = WalletLegacy::NOT_INITIALIZED;} );
    m_observerManager.notify(&IWalletLegacyObserver::initCompleted, e.code());
    return;
  } catch (std::exception&) {
    runAtomic(m_cacheMutex, [this] () {this->m_state = WalletLegacy::NOT_INITIALIZED;} );
    m_observerManager.notify(&IWalletLegacyObserver::initCompleted, make_error_code(CryptoNote::error::INTERNAL_WALLET_ERROR));
    return;
  }

  m_observerManager.notify(&IWalletLegacyObserver::initCompleted, std::error_code());
}
示例#3
0
void encStart(int tEna)
{
 clrABit();			/* clear outputs */
 clrBBit();
 clrSync();

 initABit();			/* init encoder outputs */
 initBBit();
 initSync();			/* init sync output */

 encTmrStop();			/* disable timer */
 encTmrClrIF();			/* clear interrupt flag */
 encTmrClr();			/* clear counter register */
 if (encPreScaler != 0)		/* if prescaler non zero */
  encTmrScl(encPreScaler);	/* load prescaler */
 encTmrMax(encTimer);		/* set timer period */
#if 0
 tmrInfo(TIM9);
#endif
 encState = 0;
 encCounter = 0;
 encRevCounter = 0;
 encRun = true;

 if (tEna)
 {
  encTmrSetIE();		/* enable interrupt */
  encTmrStart();   		/* turn timer on */
 }
}
示例#4
0
void WalletLegacy::initAndGenerate(const std::string& password) {
  {
    std::unique_lock<std::mutex> stateLock(m_cacheMutex);

    if (m_state != NOT_INITIALIZED) {
      throw std::system_error(make_error_code(error::ALREADY_INITIALIZED));
    }

    m_account.generate();
    m_password = password;

    initSync();
  }

  m_observerManager.notify(&IWalletLegacyObserver::initCompleted, std::error_code());
}
示例#5
0
void WalletLegacy::initWithKeys(const AccountKeys& accountKeys, const std::string& password) {
  {
    std::unique_lock<std::mutex> stateLock(m_cacheMutex);

    if (m_state != NOT_INITIALIZED) {
      throw std::system_error(make_error_code(error::ALREADY_INITIALIZED));
    }

    m_account.setAccountKeys(accountKeys);
    m_account.set_createtime(ACCOUN_CREATE_TIME_ACCURACY);
    m_password = password;

    initSync();
  }

  m_observerManager.notify(&IWalletLegacyObserver::initCompleted, std::error_code());
}
示例#6
0
int main (int argc, char** argv) {
    printf("Starting Philosopher party...\n");
    
    initSync();
    
    pthread_t *philosophers = malloc(sizeof(pthread_t) * PHILOSOPHER_AMOUNT);
    
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    
    int i;
    // JD: You had a PHILOSOPHER_AMOUNT constant yet here you have
    //     a hardcoded literal.  Do stay consistent.
    for( i = 0; i < 5; i++ ) {
        pthread_create(&philosophers[i], &attr, sitDown, (void *)i);
        printf("%s has sat down\n", names[i]);
    }

    // JD: You need to wait for the threads to stop (pthread_join)!
    //     Otherwise your program will end immediately.
    return 0;

}
示例#7
0
/// Initializer
void strat::init(eventQueue *q, rep *obj, sim *p, int pIdx)
{
  eq = q;  userObj = obj;  parent = p;  initSync();
}