-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWallet.cpp
More file actions
110 lines (87 loc) · 2.23 KB
/
Wallet.cpp
File metadata and controls
110 lines (87 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// RootCoin lib
#include "Wallet.hpp"
Node::Node(Node&& other)
: dummy(0)
{
dummy = other.dummy;
}
Node::Node() : dummy(0) {}
Wallet::Wallet(vector<Account> &accountList)
: accounts(accountList), node() {}
Wallet::Wallet()
: node() {}
Transaction Wallet::createTransaction(PublicKey to, int amount) {
Transaction tx(currentAcc->pub, to, amount);
signTransaction(tx);
return tx;
}
Transaction Wallet::createTransaction(string toAddress, int amount) {
assert(isValidAddress(toAddress));
assert(hasAccount());
Transaction tx(
currentAcc->pub.toString().c_str(),
toAddress.c_str(),
amount
);
signTransaction(tx);
return tx;
}
Signature Wallet::signTransaction(Transaction &tx) {
assert(hasAccount());
// public: Signature sign(Uint256 privateKey
return tx.sign(currentAcc->priv.get());
}
void Wallet::publishTransaction(Transaction tx) {
// 1. Sign transaction
// 2. Verify validitiy with node
// 3. Publish to node
// 4. Node publishes transaction
}
int Wallet::getBalance(const PublicKey &publicKey) {
// 1. node.getBalance();
}
const PublicKey& Wallet::getPublicKey() const {
return currentAcc->pub;
}
void Wallet::addAccount(Account account) {
// 1. Generate random private key
// 2. Create account object
accounts.push_back(account);
if(accounts.size() == 1)
currentAcc = accounts.begin();
}
void Wallet::addAccount(string privKey) {
// 1. Generate random private key
// 2. Create account object
Account account(privKey);
accounts.push_back(account);
if(accounts.size() == 1)
currentAcc = accounts.begin();
}
bool Wallet::hasAccount() const{
if(currentAcc == accounts.end()) {
return false;
}
return true;
}
Account Wallet::createAccount() {
// 1. Generate random private key
// 2. Create account object
}
bool Wallet::isValidAddress(string address) {
// @fix this logic should sit within public key class
bool valid = true;
// KEY_SIZE in bytes, 2 chars per byte, plus 1 header byte
if(address.size() != Transaction::ADDRESS_SIZE) {
valid = false;
}
return valid;
}
Account::Account(string privKey)
: priv(privKey.c_str()),
pub(CurvePoint::privateExponentToPublicPoint(priv.get()))
{}
Account::Account(Uint256 privKey)
: priv(privKey),
pub(CurvePoint::privateExponentToPublicPoint(privKey))
{}