-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transaction.cpp
81 lines (65 loc) · 1.99 KB
/
Transaction.cpp
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
#include "Transaction.h"
Transaction::Transaction() {
this->transactionHash = "";
this->fromAddress = 0;
this->toAddress = 0;
this->amount = 0;
this->gasFee = 0;
}
Transaction::Transaction(unsigned int from, unsigned int to, unsigned int amount, unsigned int gasFee) {
this->transactionHash = "";
this->fromAddress = from;
this->toAddress = to;
this->amount = amount;
this->gasFee = gasFee;
}
bool Transaction::operator ==(const Transaction& rhs) const {
return this->fromAddress == rhs.fromAddress && this->toAddress == rhs.toAddress && this->amount == rhs.amount && this->gasFee == rhs.gasFee;
}
bool Transaction::operator !=(const Transaction& rhs) const {
return !this->operator==(rhs);
}
size_t Transaction::operator()(const Transaction& rhs) const {
size_t hash = this->amount ^ rhs.amount;
hash += this->fromAddress ^ rhs.fromAddress;
hash += this->toAddress ^ rhs.toAddress;
hash += this->gasFee ^ rhs.gasFee;
return hash;
}
#pragma region GETTERS
string Transaction::getTransactionHash() {
return this->transactionHash;
}
unsigned int Transaction::getFromAddress() {
return this->fromAddress;
}
unsigned int Transaction::getToAddress() {
return this->toAddress;
}
unsigned int Transaction::getAmount() {
return this->amount;
}
unsigned int Transaction::getGasFee() {
return this->gasFee;
}
#pragma endregion
#pragma region SETTERS
void Transaction::setTransactionHash(string transactionHash) {
this->transactionHash = transactionHash;
}
void Transaction::setFromAddress(unsigned int fromAddress) {
this->fromAddress = fromAddress;
}
void Transaction::setToAddress(unsigned int toAddress) {
this->toAddress = toAddress;
}
void Transaction::setAmount(unsigned int amount) {
this->amount = amount;
}
void Transaction::setGasFee(unsigned int gasFee) {
this->gasFee = gasFee;
}
#pragma endregion
string Transaction::toString() {
return to_string(this->getAmount()) + "_" + to_string(this->getFromAddress()) + "_" + to_string(this->getToAddress()) + "_" + to_string(this->getGasFee());
}