├── .editorconfig
├── .gitignore
├── .idea
└── vcs.xml
├── AUTHORS
├── LICENSE
├── Makefile
├── abc-cli
├── abc-watcher
├── abcd
├── AccountPaths.hpp
├── Context.cpp
├── Context.hpp
├── Export.cpp
├── Export.hpp
├── General.cpp
├── General.hpp
├── RootPaths.cpp
├── RootPaths.hpp
├── WalletPaths.hpp
├── account
│ ├── Account.cpp
│ ├── Account.hpp
│ ├── AccountCategories.cpp
│ ├── AccountCategories.hpp
│ ├── AccountSettings.cpp
│ ├── AccountSettings.hpp
│ ├── PluginData.cpp
│ ├── PluginData.hpp
│ ├── WalletList.cpp
│ └── WalletList.hpp
├── bitcoin
│ ├── Testnet.cpp
│ ├── Testnet.hpp
│ ├── Text.cpp
│ ├── Text.hpp
│ ├── Typedefs.hpp
│ ├── Utility.cpp
│ ├── Utility.hpp
│ ├── Watcher.cpp
│ ├── Watcher.hpp
│ ├── WatcherBridge.cpp
│ ├── WatcherBridge.hpp
│ ├── cache
│ │ ├── AddressCache.cpp
│ │ ├── AddressCache.hpp
│ │ ├── BlockCache.cpp
│ │ ├── BlockCache.hpp
│ │ ├── Cache.cpp
│ │ ├── Cache.hpp
│ │ ├── ServerCache.cpp
│ │ ├── ServerCache.hpp
│ │ ├── TxCache.cpp
│ │ └── TxCache.hpp
│ ├── network
│ │ ├── IBitcoinConnection.hpp
│ │ ├── LibbitcoinConnection.cpp
│ │ ├── LibbitcoinConnection.hpp
│ │ ├── StratumConnection.cpp
│ │ ├── StratumConnection.hpp
│ │ ├── TcpConnection.cpp
│ │ ├── TcpConnection.hpp
│ │ ├── TxUpdater.cpp
│ │ └── TxUpdater.hpp
│ └── spend
│ │ ├── AirbitzFee.cpp
│ │ ├── AirbitzFee.hpp
│ │ ├── Broadcast.cpp
│ │ ├── Broadcast.hpp
│ │ ├── Inputs.cpp
│ │ ├── Inputs.hpp
│ │ ├── Outputs.cpp
│ │ ├── Outputs.hpp
│ │ ├── PaymentProto.cpp
│ │ ├── PaymentProto.hpp
│ │ ├── Spend.cpp
│ │ ├── Spend.hpp
│ │ ├── Sweep.cpp
│ │ ├── Sweep.hpp
│ │ └── paymentrequest.proto
├── crypto
│ ├── Crypto.cpp
│ ├── Crypto.hpp
│ ├── Encoding.cpp
│ ├── Encoding.hpp
│ ├── OtpKey.cpp
│ ├── OtpKey.hpp
│ ├── Random.cpp
│ ├── Random.hpp
│ ├── Scrypt.cpp
│ └── Scrypt.hpp
├── exchange
│ ├── Currency.cpp
│ ├── Currency.hpp
│ ├── ExchangeCache.cpp
│ ├── ExchangeCache.hpp
│ ├── ExchangeSource.cpp
│ └── ExchangeSource.hpp
├── http
│ ├── Http.cpp
│ ├── Http.hpp
│ ├── HttpRequest.cpp
│ ├── HttpRequest.hpp
│ ├── Uri.cpp
│ └── Uri.hpp
├── json
│ ├── JsonArray.cpp
│ ├── JsonArray.hpp
│ ├── JsonBox.cpp
│ ├── JsonBox.hpp
│ ├── JsonObject.cpp
│ ├── JsonObject.hpp
│ ├── JsonPtr.cpp
│ ├── JsonPtr.hpp
│ ├── JsonSnrp.cpp
│ └── JsonSnrp.hpp
├── login
│ ├── Bitid.cpp
│ ├── Bitid.hpp
│ ├── Login.cpp
│ ├── Login.hpp
│ ├── LoginPassword.cpp
│ ├── LoginPassword.hpp
│ ├── LoginPin.cpp
│ ├── LoginPin.hpp
│ ├── LoginPin2.cpp
│ ├── LoginPin2.hpp
│ ├── LoginRecovery.cpp
│ ├── LoginRecovery.hpp
│ ├── LoginRecovery2.cpp
│ ├── LoginRecovery2.hpp
│ ├── LoginStore.cpp
│ ├── LoginStore.hpp
│ ├── Otp.cpp
│ ├── Otp.hpp
│ ├── RecoveryQuestions.cpp
│ ├── RecoveryQuestions.hpp
│ ├── Sharing.cpp
│ ├── Sharing.hpp
│ ├── json
│ │ ├── AuthJson.cpp
│ │ ├── AuthJson.hpp
│ │ ├── KeyJson.hpp
│ │ ├── LoginJson.cpp
│ │ ├── LoginJson.hpp
│ │ └── LoginPackages.hpp
│ └── server
│ │ ├── AirbitzRequest.cpp
│ │ ├── AirbitzRequest.hpp
│ │ ├── LoginServer.cpp
│ │ ├── LoginServer.hpp
│ │ ├── Pinning.cpp
│ │ └── Pinning.hpp
├── util
│ ├── AutoFree.hpp
│ ├── Data.cpp
│ ├── Data.hpp
│ ├── Debug.cpp
│ ├── Debug.hpp
│ ├── FileIO.cpp
│ ├── FileIO.hpp
│ ├── Status.cpp
│ ├── Status.hpp
│ ├── Sync.cpp
│ ├── Sync.hpp
│ ├── U08Buf.cpp
│ ├── U08Buf.hpp
│ ├── Util.cpp
│ └── Util.hpp
└── wallet
│ ├── AddressDb.cpp
│ ├── AddressDb.hpp
│ ├── Metadata.cpp
│ ├── Metadata.hpp
│ ├── Receive.cpp
│ ├── Receive.hpp
│ ├── TxDb.cpp
│ ├── TxDb.hpp
│ ├── Wallet.cpp
│ └── Wallet.hpp
├── astyle-options
├── cli
├── Command.cpp
├── Command.hpp
├── Main.cpp
├── abc-cli-bash-completion.sh
├── airbitz.conf
├── ca-certificates.crt
├── commands
│ ├── Account.cpp
│ ├── Address.cpp
│ ├── Bitid.cpp
│ ├── Categories.cpp
│ ├── Commands.cpp
│ ├── Exchange.cpp
│ ├── Hiddenbits.cpp
│ ├── Lobby.cpp
│ ├── Otp.cpp
│ ├── Pin.cpp
│ ├── Plugin.cpp
│ ├── Recovery.cpp
│ ├── Recovery2.cpp
│ ├── Repo.cpp
│ ├── Settings.cpp
│ ├── Spend.cpp
│ ├── Stratum.cpp
│ ├── Wallet.cpp
│ └── Watcher.cpp
└── doc
│ ├── .gitignore
│ ├── README.md
│ └── abc-cli.pod
├── deps
├── .gitignore
├── Makefile
├── abc-cli
├── abc-watcher
├── classes
│ ├── android
│ ├── android.toolchain.cmake
│ ├── common
│ ├── ios
│ ├── ios.toolchain.cmake
│ ├── lib
│ ├── native
│ ├── native.cmake
│ ├── osx
│ └── osx.toolchain.cmake
├── documentation.md
├── make-testnet
├── mk-abc-only
├── recipes
│ ├── abc
│ │ └── abc.recipe
│ ├── boost
│ │ ├── boost.recipe
│ │ ├── fix-asio-android.patch
│ │ └── user-config.jam
│ ├── curl
│ │ └── curl.recipe
│ ├── jansson
│ │ └── jansson.recipe
│ ├── libbitcoin
│ │ ├── config.patch
│ │ └── libbitcoin.recipe
│ ├── libcsv
│ │ └── libcsv.recipe
│ ├── libgit2
│ │ ├── ios-build.patch
│ │ ├── libgit2.recipe
│ │ ├── pinning.patch
│ │ └── timeout.patch
│ ├── libqrencode
│ │ └── libqrencode.recipe
│ ├── libsecp256k1
│ │ ├── libsecp256k1.recipe
│ │ └── optimize.patch
│ ├── libsodium
│ │ └── libsodium.recipe
│ ├── ndk
│ │ ├── langinfo.h
│ │ └── ndk.recipe
│ ├── openssl
│ │ └── openssl.recipe
│ ├── protobuf
│ │ └── protobuf.recipe
│ ├── zeromq
│ │ ├── ios-crash.patch
│ │ └── zeromq.recipe
│ └── zlib
│ │ └── zlib.recipe
└── run.sh
├── minilibs
├── catch
│ ├── catch.hpp
│ └── readme.md
├── git-sync
│ ├── .gitignore
│ ├── Makefile
│ ├── main.c
│ ├── readme.md
│ ├── sync.c
│ ├── sync.h
│ └── test.c
├── libbitcoin-client
│ ├── client.hpp
│ ├── message_stream.hpp
│ ├── obelisk_codec.cpp
│ ├── obelisk_codec.hpp
│ ├── obelisk_router.cpp
│ ├── obelisk_router.hpp
│ ├── obelisk_types.hpp
│ ├── sleeper.hpp
│ ├── zeromq_socket.cpp
│ └── zeromq_socket.hpp
└── scrypt
│ ├── .gitignore
│ ├── Makefile
│ ├── crypto_scrypt.c
│ ├── crypto_scrypt.h
│ ├── readme.md
│ └── sysendian.h
├── readme.md
├── remove-build-tags.sh
├── src
├── .gitignore
├── ABC.cpp
├── ABC.h
├── HandleCache.hpp
├── LoginShim.cpp
├── LoginShim.hpp
├── TxDetails.cpp
├── TxDetails.hpp
├── TxInfo.cpp
├── TxInfo.hpp
└── Version.h.in
├── style.md
├── test
├── Bitcoin.cpp
├── Bitid.cpp
├── Crypto.cpp
├── Encoding.cpp
├── Json.cpp
├── Main.cpp
├── OtpKey.cpp
├── Scrypt.cpp
├── TxCache.cpp
└── Uri.cpp
└── util
├── .gitignore
├── airbitz-keygen.sh
├── airbitz-pubkeygen.sh
└── git-hooks
└── pre-commit
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | end_of_line = lf
5 | indent_size = 4
6 | indent_style = space
7 | insert_final_newline = true
8 | trim_trailing_whitespace = true
9 |
10 | [Makefile]
11 | indent_size = 8
12 | indent_style = tab
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.vpj
3 | *.vpw
4 | *.vpwhistu
5 | *~
6 | .*.swp
7 | .DS_Store
8 | /build
9 | /codegen
10 | *.idea*
11 | *CMakeLists*
12 | pod2htmd.tmp
13 |
14 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | Authors:
2 |
3 | * Tim Horton
4 | tim 'at' airbitz.co
5 |
6 | * William Swanson
7 | william 'at' airbitz.co
8 |
9 | * Paul Puey
10 | paul 'at' airbitz.co
11 |
12 | * Adam Harris
13 | adam 'at' dittylabs.com
14 |
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Airbitz Inc
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms are permitted provided that
5 | the following conditions are met:
6 |
7 | 1. Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 | 2. Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation
11 | and/or other materials provided with the distribution.
12 | 3. Redistribution or use of modified source code requires the express written
13 | permission of Airbitz Inc.
14 |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 |
26 | The views and conclusions contained in the software and documentation are those
27 | of the authors and should not be interpreted as representing official policies,
28 | either expressed or implied, of the Airbitz Project.
29 |
30 |
31 |
--------------------------------------------------------------------------------
/abc-cli:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | program=build/abc-cli
3 | make $program && ./$program "$@"
4 |
--------------------------------------------------------------------------------
/abc-watcher:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | program=build/abc-watcher
3 | make $program && ./$program "$@"
4 |
--------------------------------------------------------------------------------
/abcd/AccountPaths.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #ifndef ABCD_ACCOUNT_PATHS_HPP
9 | #define ABCD_ACCOUNT_PATHS_HPP
10 |
11 | #include "util/Status.hpp"
12 |
13 | namespace abcd {
14 |
15 | /**
16 | * Knows how to calculate paths within a login directory.
17 | */
18 | class AccountPaths
19 | {
20 | public:
21 | AccountPaths(): ok_(false) {}
22 | AccountPaths(const std::string &dir): ok_(true), dir_(dir) {}
23 |
24 | bool ok() const { return ok_; }
25 |
26 | // Directories:
27 | const std::string &dir() const { return dir_; }
28 | std::string syncDir() const { return dir_ + "sync/"; }
29 | std::string walletsDir() const { return dir_ + "sync/Wallets/"; }
30 |
31 | // Files:
32 | std::string carePackagePath() const { return dir_ + "CarePackage.json"; }
33 | std::string loginPackagePath() const { return dir_ + "LoginPackage.json"; }
34 | std::string pinPackagePath() const { return dir_ + "PinPackage.json"; }
35 | std::string otpKeyPath() const { return dir_ + "OtpKey.json"; }
36 | std::string pin2KeyPath() const { return dir_ + "Pin2Key.json"; }
37 | std::string recovery2KeyPath() const { return dir_ + "Recovery2Key.json"; }
38 | std::string rootKeyPath() const { return dir_ + "RootKey.json"; }
39 | std::string stashPath() const { return dir_ + "Stash.json"; }
40 |
41 | private:
42 | bool ok_;
43 | std::string dir_;
44 | };
45 |
46 | } // namespace abcd
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/abcd/Context.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #include "Context.hpp"
9 | #include "bitcoin/cache/BlockCache.hpp"
10 | #include "exchange/ExchangeCache.hpp"
11 | #include "bitcoin/cache/ServerCache.hpp"
12 |
13 | namespace abcd {
14 |
15 | std::unique_ptr gContext;
16 |
17 | Context::~Context()
18 | {
19 | delete &blockCache;
20 | delete &exchangeCache;
21 | }
22 |
23 | Context::Context(const std::string &rootDir, const std::string &certPath,
24 | const std::string &apiKey,
25 | const std::string &accountType,
26 | const std::string &hiddenBitsKey):
27 | apiKey_(apiKey),
28 | accountType_(accountType),
29 | hiddenBitsKey_(hiddenBitsKey),
30 | paths(rootDir, certPath),
31 | blockCache(*new BlockCache(paths.blockCachePath())),
32 | exchangeCache(*new ExchangeCache(paths.exchangeCachePath())),
33 | serverCache(*new ServerCache(paths.serverScoresPath()))
34 | {
35 | blockCache.load().log(); // Failure is fine
36 | }
37 |
38 | } // namespace abcd
39 |
--------------------------------------------------------------------------------
/abcd/Context.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #ifndef ABCD_CONTEXT_H
9 | #define ABCD_CONTEXT_H
10 |
11 | #include "RootPaths.hpp"
12 | #include
13 |
14 | namespace abcd {
15 |
16 | class BlockCache;
17 | class ExchangeCache;
18 | class ServerCache;
19 |
20 | /**
21 | * An object holding app-wide information, such as paths.
22 | */
23 | class Context
24 | {
25 | public:
26 | ~Context();
27 | Context(const std::string &rootDir, const std::string &certPath,
28 | const std::string &apiKey,
29 | const std::string &accountType,
30 | const std::string &hiddenBitsKey);
31 |
32 | const std::string &apiKey() const { return apiKey_; }
33 | const std::string &accountType() const { return accountType_; }
34 | const std::string &hiddenBitsKey() const { return hiddenBitsKey_; }
35 |
36 | private:
37 | const std::string apiKey_;
38 | const std::string accountType_;
39 | const std::string hiddenBitsKey_;
40 |
41 | public:
42 | RootPaths paths;
43 | BlockCache &blockCache;
44 | ExchangeCache &exchangeCache;
45 | ServerCache &serverCache;
46 | };
47 |
48 | /**
49 | * The global context instance.
50 | */
51 | extern std::unique_ptr gContext;
52 |
53 | } // namespace abcd
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/abcd/Export.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 | /**
8 | * @file
9 | * Functions for exporting wallet meta-data.
10 | */
11 |
12 | #ifndef ABC_Export_h
13 | #define ABC_Export_h
14 |
15 | #include "util/Status.hpp"
16 |
17 | namespace abcd {
18 |
19 | tABC_CC ABC_ExportFormatCsv(tABC_TxInfo **pTransactions,
20 | unsigned int iTransactionCount,
21 | char **szCsvData,
22 | tABC_Error *pError,
23 | std::string currency);
24 |
25 | Status
26 | exportFormatQBO(std::string &result, tABC_TxInfo **pTransactions,
27 | unsigned int iTransactionCount, std::string currency);
28 |
29 | } // namespace abcd
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/abcd/RootPaths.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #ifndef ABCD_ROOT_PATHS_HPP
9 | #define ABCD_ROOT_PATHS_HPP
10 |
11 | #include "util/Status.hpp"
12 | #include
13 |
14 | namespace abcd {
15 |
16 | class AccountPaths;
17 | class WalletPaths;
18 |
19 | /**
20 | * Knows how to calculate paths at the top-level of the app.
21 | */
22 | class RootPaths
23 | {
24 | public:
25 | RootPaths(const std::string &rootDir, const std::string &certPath);
26 |
27 | // Directories:
28 | const std::string &rootDir() const { return dir_; }
29 | std::string accountsDir() const;
30 | std::string walletsDir() const { return dir_ + "Wallets/"; }
31 |
32 | /**
33 | * Lists the accounts on the device.
34 | */
35 | std::list
36 | accountList();
37 |
38 | /**
39 | * Finds the account directory for a particular username.
40 | * Returns an empty string if the account does not exist on the device.
41 | */
42 | Status
43 | accountDir(AccountPaths &result, const std::string &username);
44 |
45 | /**
46 | * Creates a fresh directory for a new account.
47 | */
48 | Status
49 | accountDirNew(AccountPaths &result, const std::string &username);
50 |
51 | /**
52 | * Returns the directory name for a particular wallet.
53 | */
54 | WalletPaths
55 | walletDir(const std::string &id);
56 |
57 | // Individual files:
58 | const std::string &certPath() const { return certPath_; }
59 | std::string blockCachePath() const { return dir_ + "Blocks.json"; }
60 | std::string exchangeCachePath() const { return dir_ + "Exchange.json"; }
61 | std::string feeCachePath() const { return dir_ + "Fees.json"; }
62 | std::string twentyOneFeeCachePath() const { return dir_ + "TwentyOneFees.json"; }
63 | std::string generalPath() const { return dir_ + "Servers.json"; }
64 | std::string serverScoresPath() const { return dir_ + "ServerScores.json"; }
65 | std::string questionsPath() const { return dir_ + "Questions.json"; }
66 | std::string logPath() const { return dir_ + "abc.log"; }
67 | std::string logPrevPath() const { return dir_ + "abc-prev.log"; }
68 |
69 | private:
70 | const std::string dir_;
71 | const std::string certPath_;
72 | };
73 |
74 | } // namespace abcd
75 |
76 | #endif
77 |
--------------------------------------------------------------------------------
/abcd/WalletPaths.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016, AirBitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #ifndef ABCD_WALLET_PATHS_HPP
9 | #define ABCD_WALLET_PATHS_HPP
10 |
11 | #include "util/Status.hpp"
12 | #include
13 |
14 | namespace abcd {
15 |
16 | /**
17 | * Knows how to calculate paths within a wallet directory.
18 | */
19 | class WalletPaths
20 | {
21 | public:
22 | WalletPaths(const std::string &walletDir): dir_(walletDir) {}
23 |
24 | // Directories:
25 | const std::string &dir() const { return dir_; }
26 | std::string syncDir() const { return dir_ + "sync/"; }
27 | std::string addressesDir() const { return dir_ + "sync/Addresses/"; }
28 | std::string txsDir() const { return dir_ + "sync/Transactions/"; }
29 |
30 | // Files:
31 | std::string currencyPath() const { return dir_ + "sync/Currency.json"; }
32 | std::string namePath() const { return dir_ + "sync/WalletName.json"; }
33 | std::string cachePath() const { return dir_ + "Cache.json"; }
34 | std::string cachePathOld() const { return dir_ + "watcher.ser"; }
35 |
36 | private:
37 | std::string dir_;
38 | };
39 |
40 | } // namespace abcd
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/abcd/account/Account.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #include "Account.hpp"
9 | #include "../Context.hpp"
10 | #include "../crypto/Encoding.hpp"
11 | #include "../login/Login.hpp"
12 | #include "../login/json/KeyJson.hpp"
13 | #include "../util/Sync.hpp"
14 |
15 | namespace abcd {
16 |
17 | Status
18 | Account::create(std::shared_ptr &result, Login &login)
19 | {
20 | AccountRepoJson repoJson;
21 | ABC_CHECK(login.repoFind(repoJson, gContext->accountType(), true));
22 | DataChunk dataKey;
23 | DataChunk syncKey;
24 | ABC_CHECK(base64Decode(dataKey, repoJson.dataKey()));
25 | ABC_CHECK(base64Decode(syncKey, repoJson.syncKey()));
26 | std::shared_ptr out(new Account(login, dataKey, syncKey));
27 | ABC_CHECK(out->load());
28 |
29 | result = std::move(out);
30 | return Status();
31 | }
32 |
33 | Status
34 | Account::sync(bool &dirty)
35 | {
36 | ABC_CHECK(syncRepo(dir(), syncKey_, dirty));
37 | if (dirty)
38 | ABC_CHECK(load());
39 |
40 | return Status();
41 | }
42 |
43 | Account::Account(Login &login, DataSlice dataKey, DataSlice syncKey):
44 | login(login),
45 | parent_(login.shared_from_this()),
46 | dir_(login.paths.syncDir()),
47 | dataKey_(dataKey.begin(), dataKey.end()),
48 | syncKey_(base16Encode(syncKey)),
49 | wallets(*this)
50 | {}
51 |
52 | Status
53 | Account::load()
54 | {
55 | // If the sync dir doesn't exist, create it:
56 | const auto tempPath = login.paths.dir() + "tmp/";
57 | ABC_CHECK(syncEnsureRepo(dir(), tempPath, syncKey_));
58 |
59 | ABC_CHECK(wallets.load());
60 | return Status();
61 | }
62 |
63 | } // namespace abcd
64 |
--------------------------------------------------------------------------------
/abcd/account/Account.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #ifndef ABCD_ACCOUNT_ACCOUNT_HPP
9 | #define ABCD_ACCOUNT_ACCOUNT_HPP
10 |
11 | #include "WalletList.hpp"
12 | #include
13 |
14 | namespace abcd {
15 |
16 | class Login;
17 |
18 | /**
19 | * Manages the account sync directory.
20 | */
21 | class Account:
22 | public std::enable_shared_from_this
23 | {
24 | public:
25 | Login &login;
26 |
27 | static Status
28 | create(std::shared_ptr &result, Login &login);
29 |
30 | const std::string &dir() const { return dir_; }
31 | const DataChunk &dataKey() const { return dataKey_; }
32 |
33 | /**
34 | * Syncs the account with the file server.
35 | * This is a blocking network operation.
36 | */
37 | Status
38 | sync(bool &dirty);
39 |
40 | private:
41 | const std::shared_ptr parent_;
42 | const std::string dir_;
43 | const DataChunk dataKey_;
44 | const std::string syncKey_;
45 |
46 | Account(Login &login, DataSlice dataKey, DataSlice syncKey);
47 |
48 | Status
49 | load();
50 |
51 | public:
52 | WalletList wallets;
53 |
54 | // Set to the current PIN when the settings are loaded.
55 | // Used to detect changes to the PIN.
56 | std::string pin;
57 | };
58 |
59 | } // namespace abcd
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/abcd/account/AccountCategories.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #include "AccountCategories.hpp"
9 | #include "Account.hpp"
10 | #include "../json/JsonArray.hpp"
11 | #include "../json/JsonObject.hpp"
12 | #include "../login/Login.hpp"
13 |
14 | namespace abcd {
15 |
16 | struct CategoriesJson:
17 | public JsonObject
18 | {
19 | ABC_JSON_VALUE(categories, "categories", JsonArray);
20 | };
21 |
22 | static std::string
23 | categoriesPath(const Account &account)
24 | {
25 | return account.dir() + "Categories.json";
26 | }
27 |
28 | Status
29 | accountCategoriesSave(const Account &account,
30 | const AccountCategories &categories)
31 | {
32 | JsonArray arrayJson;
33 | for (auto &i: categories)
34 | {
35 | ABC_CHECK(arrayJson.append(json_string(i.c_str())));
36 | }
37 |
38 | CategoriesJson json;
39 | ABC_CHECK(json.categoriesSet(arrayJson));
40 | ABC_CHECK(json.save(categoriesPath(account), account.dataKey()));
41 |
42 | return Status();
43 | }
44 |
45 | Status
46 | accountCategoriesLoad(AccountCategories &result, const Account &account)
47 | {
48 | AccountCategories out;
49 |
50 | CategoriesJson json;
51 | ABC_CHECK(json.load(categoriesPath(account), account.dataKey()));
52 |
53 | auto arrayJson = json.categories();
54 | size_t size = arrayJson.size();
55 | for (size_t i = 0; i < size; i++)
56 | {
57 | auto stringJson = arrayJson[i];
58 | if (!json_is_string(stringJson.get()))
59 | return ABC_ERROR(ABC_CC_JSONError, "Category is not a string");
60 |
61 | out.insert(json_string_value(stringJson.get()));
62 | }
63 |
64 | result = std::move(out);
65 | return Status();
66 | }
67 |
68 | Status
69 | accountCategoriesAdd(const Account &account, const std::string &category)
70 | {
71 | AccountCategories categories;
72 | accountCategoriesLoad(categories, account);
73 | categories.insert(category);
74 | ABC_CHECK(accountCategoriesSave(account, categories));
75 | return Status();
76 | }
77 |
78 | Status
79 | accountCategoriesRemove(const Account &account, const std::string &category)
80 | {
81 | AccountCategories categories;
82 | ABC_CHECK(accountCategoriesLoad(categories, account));
83 | categories.erase(category);
84 | ABC_CHECK(accountCategoriesSave(account, categories));
85 | return Status();
86 | }
87 |
88 | } // namespace abcd
89 |
--------------------------------------------------------------------------------
/abcd/account/AccountCategories.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #ifndef ABCD_ACCOUNT_ACCOUNT_CATEGORIES_HPP
9 | #define ABCD_ACCOUNT_ACCOUNT_CATEGORIES_HPP
10 |
11 | #include "../util/Status.hpp"
12 | #include
13 |
14 | namespace abcd {
15 |
16 | class Account;
17 |
18 | typedef std::set AccountCategories;
19 |
20 | /**
21 | * Loads the categories from an account.
22 | */
23 | Status
24 | accountCategoriesLoad(AccountCategories &result, const Account &account);
25 |
26 | /**
27 | * Adds a category to the account.
28 | */
29 | Status
30 | accountCategoriesAdd(const Account &account, const std::string &category);
31 |
32 | /**
33 | * Removes a category from the account.
34 | */
35 | Status
36 | accountCategoriesRemove(const Account &account, const std::string &category);
37 |
38 | } // namespace abcd
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/abcd/account/AccountSettings.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #ifndef ABCD_ACCOUNT_ACCOUNT_SETTINGS_HPP
9 | #define ABCD_ACCOUNT_ACCOUNT_SETTINGS_HPP
10 |
11 | #include "../util/Status.hpp"
12 |
13 | #define DEFAULT_SERVER_LIST "stratum://electrum.airbitz.co\nstratum://electrum-bu-az-weuro.airbitz.co:50001\nstratum://electrum-bu-az-wjapan.airbitz.co:50001\nstratum://electrum-bc-az-eusa.airbitz.co:50001"
14 |
15 | // Miminum possible server string. ie. "stratum://e.c:1"
16 | #define SERVER_STRING_LEN_MINIMUM 15
17 |
18 | namespace abcd {
19 |
20 | class Account;
21 | class Login;
22 |
23 | /**
24 | * Loads the settings from an account.
25 | * Returns default settings if anything goes wrong.
26 | */
27 | tABC_AccountSettings *
28 | accountSettingsLoad(Account &account);
29 |
30 | /**
31 | * Saves the settings for an account.
32 | */
33 | Status
34 | accountSettingsSave(Account &account, tABC_AccountSettings *pSettings);
35 |
36 | /**
37 | * Frees the account settings structure, along with its contents.
38 | */
39 | void
40 | accountSettingsFree(tABC_AccountSettings *pSettings);
41 |
42 | } // namespace abcd
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/abcd/account/PluginData.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #ifndef ABCD_ACCOUNT_PLUGIN_DATA_HPP
9 | #define ABCD_ACCOUNT_PLUGIN_DATA_HPP
10 |
11 | #include "../util/Status.hpp"
12 | #include
13 |
14 | namespace abcd {
15 |
16 | class Account;
17 |
18 | /**
19 | * Lists the plugin key/value stores in the account.
20 | * This mainly exists for diagnostics,
21 | * since the idea is that all plugins are sandboxed by their plugin id.
22 | * There shouldn't be any code that needs to list the plugin id's,
23 | * since the list should be static and know ahead of time.
24 | */
25 | std::list
26 | pluginDataList(const Account &account);
27 |
28 | /**
29 | * Lists the keys in a plugin key/value store.
30 | */
31 | std::list
32 | pluginDataKeys(const Account &account, const std::string &plugin);
33 |
34 | /**
35 | * Retreives an item from the plugin key/value store.
36 | * @param plugin The plugin's unique ID.
37 | * @param key The data location. Merges happen at the key level,
38 | * so the account may contain a mix of keys from different devices.
39 | * The key contents are atomic, however. Place data accordingly.
40 | * @param data The value stored with the key.
41 | */
42 | Status
43 | pluginDataGet(const Account &account, const std::string &plugin,
44 | const std::string &key, std::string &data);
45 |
46 | /**
47 | * Saves an item to the plugin key/value store.
48 | */
49 | Status
50 | pluginDataSet(const Account &account, const std::string &plugin,
51 | const std::string &key, const std::string &data);
52 |
53 | /**
54 | * Deletes an item from the plugin key/value store.
55 | */
56 | Status
57 | pluginDataRemove(const Account &account, const std::string &plugin,
58 | const std::string &key);
59 |
60 | /**
61 | * Removes the entire key/value store for a particular plugin.
62 | */
63 | Status
64 | pluginDataClear(const Account &account, const std::string &plugin);
65 |
66 | } // namespace abcd
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/abcd/account/WalletList.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Airbitz, Inc.
3 | * All rights reserved.
4 | *
5 | * See the LICENSE file for more information.
6 | */
7 |
8 | #ifndef ABCD_ACCOUNT_WALLET_LIST_HPP
9 | #define ABCD_ACCOUNT_WALLET_LIST_HPP
10 |
11 | #include "../json/JsonPtr.hpp"
12 | #include
13 | #include