Esempio n. 1
0
Status
Wallet::balance(int64_t &result)
{
    // We cannot put a mutex in `balanceDirty()`, since that will deadlock
    // the transaction database during the balance calculation.
    // Instead, we access `balanceDirty_` atomically outside the mutex:
    bool dirty = balanceDirty_;
    balanceDirty_ = false;

    std::lock_guard<std::mutex> lock(mutex_);
    if (dirty)
    {
        tABC_TxInfo **aTransactions = nullptr;
        unsigned int nTxCount = 0;

        ABC_CHECK_OLD(ABC_TxGetTransactions(*this,
                                            ABC_GET_TX_ALL_TIMES, ABC_GET_TX_ALL_TIMES,
                                            &aTransactions, &nTxCount, &error));
        ABC_CHECK_OLD(ABC_BridgeFilterTransactions(*this,
                      aTransactions, &nTxCount, &error));

        balance_ = 0;
        for (unsigned i = 0; i < nTxCount; ++i)
            balance_ += aTransactions[i]->pDetails->amountSatoshi;

        // TODO: Leaks if ABC_BridgeFilterTransactions fails.
        ABC_TxFreeTransactions(aTransactions, nTxCount);
    }

    result = balance_;
    return Status();
}
Esempio n. 2
0
Status
otpAuthRemove(Login &login)
{
    AutoU08Buf LP1;
    ABC_CHECK_OLD(ABC_LoginGetServerKey(login, &LP1, &error));
    ABC_CHECK_OLD(ABC_LoginServerOtpDisable(login.lobby, LP1, &error));

    return Status();
}
Esempio n. 3
0
Status
otpResetRemove(Login &login)
{
    AutoU08Buf LP1;
    ABC_CHECK_OLD(ABC_LoginGetServerKey(login, &LP1, &error));
    ABC_CHECK_OLD(ABC_LoginServerOtpResetCancelPending(login.lobby, LP1, &error));

    return Status();
}
Esempio n. 4
0
Status
otpAuthGet(Login &login, bool &enabled, long &timeout)
{
    AutoU08Buf LP1;
    ABC_CHECK_OLD(ABC_LoginGetServerKey(login, &LP1, &error));
    ABC_CHECK_OLD(ABC_LoginServerOtpStatus(login.lobby, LP1, &enabled, &timeout, &error));

    return Status();
}
Esempio n. 5
0
Status
JsonBox::decrypt(DataChunk &result, DataSlice key)
{
    DataChunk nonce;
    ABC_CHECK(nonceOk());
    ABC_CHECK(base16Decode(nonce, this->nonce()));

    DataChunk cyphertext;
    ABC_CHECK(cyphertextOk());
    ABC_CHECK(base64Decode(cyphertext, this->cyphertext()));

    switch (type())
    {
    case AES256_CBC_AIRBITZ:
    {
        ABC_CHECK_OLD(ABC_CryptoDecryptAES256Package(result,
                      cyphertext, key, nonce,
                      &error));
        return Status();
    }

    default:
        return ABC_ERROR(ABC_CC_DecryptError, "Unknown encryption type");
    }
}
Esempio n. 6
0
Status
loginServerWalletActivate(const Login &login, const std::string &syncKey)
{
    ABC_CHECK_OLD(ABC_WalletServerRepoPost(login.lobby, login.authKey(),
                                           syncKey, "wallet/activate", &error));
    return Status();
}
Esempio n. 7
0
Status
LoginServerWalletActivate(const Lobby &lobby, tABC_U08Buf LP1, const char *syncKey)
{
    ABC_CHECK_OLD(ABC_WalletServerRepoPost(lobby, LP1, syncKey,
        ABC_SERVER_WALLET_ACTIVATE_PATH, &error));
    return Status();
}
Esempio n. 8
0
Status
otpResetSet(Lobby &lobby)
{
    ABC_CHECK_OLD(ABC_LoginServerOtpReset(lobby, &error));

    return Status();
}
Esempio n. 9
0
Status
otpResetGet(std::list<std::string> &result,
    const std::list<std::string> &usernames)
{
    // List the users:
    std::list<DataChunk> authIds;
    for (const auto &i: usernames)
    {
        std::shared_ptr<Lobby> lobby;
        ABC_CHECK(Lobby::create(lobby, i));
        auto authId = lobby->authId();
        authIds.emplace_back(authId.begin(), authId.end());
    }

    // Make the request:
    std::list<bool> flags;
    ABC_CHECK_OLD(ABC_LoginServerOtpPending(authIds, flags, &error));

    // Smush the results:
    result.clear();
    auto i = flags.begin();
    auto j = usernames.begin();
    while (i != flags.end() && j != usernames.end())
    {
        if (*i)
            result.push_back(*j);
        ++i; ++j;
    }

    return Status();
}
Esempio n. 10
0
Status
otpAuthSet(Login &login, long timeout)
{
    // Install a key if needed:
    if (!login.lobby.otpKey())
    {
        OtpKey random;
        ABC_CHECK(random.create());
        login.lobby.otpKeySet(random);
    }

    AutoU08Buf LP1;
    ABC_CHECK_OLD(ABC_LoginGetServerKey(login, &LP1, &error));
    ABC_CHECK_OLD(ABC_LoginServerOtpEnable(login.lobby, LP1,
        login.lobby.otpKey()->encodeBase32().c_str(), timeout, &error));

    return Status();
}
Esempio n. 11
0
Status
pluginDataClear(const Account &account, const std::string &plugin)
{
    std::string directory = pluginDirectory(account, plugin);

    if (fileExists(directory))
        ABC_CHECK_OLD(ABC_FileIODeleteRecursive(directory.c_str(), &error));

    return Status();
}
Esempio n. 12
0
Status
pluginDataRemove(const Account &account, const std::string &plugin,
    const std::string &key)
{
    std::string filename = keyFilename(account, plugin, key);

    if (fileExists(filename))
        ABC_CHECK_OLD(ABC_FileIODeleteFile(filename.c_str(), &error));

    return Status();
}
Esempio n. 13
0
Status
JsonBox::encrypt(DataSlice data, DataSlice key)
{
    DataChunk nonce;
    AutoU08Buf cyphertext;
    ABC_CHECK_OLD(ABC_CryptoEncryptAES256Package(data, key,
                  &cyphertext, nonce, &error));

    ABC_CHECK(typeSet(AES256_CBC_AIRBITZ));
    ABC_CHECK(nonceSet(base16Encode(nonce)));
    ABC_CHECK(cyphertextSet(base64Encode(cyphertext)));

    return Status();
}
Esempio n. 14
0
Status
AddressJson::unpack(Address &result)
{
    Address out;

    // Main json:
    ABC_CHECK(indexOk());
    out.index = index();
    ABC_CHECK(addressOk());
    out.address = address();

    // State json:
    AddressStateJson stateJson = state();
    out.recyclable = stateJson.recyclable();
    out.time = stateJson.time();

    // Details json:
    AutoFree<tABC_TxDetails, ABC_TxDetailsFree> pDetails;
    ABC_CHECK_OLD(ABC_TxDetailsDecode(get(), &pDetails.get(), &error));
    out.metadata = TxMetadata(pDetails);

    result = std::move(out);
    return Status();
}