Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
mastercore_tx.h
Go to the documentation of this file.
1 #ifndef _MASTERCOIN_TX
2 #define _MASTERCOIN_TX 1
3 
4 #include "mastercore.h"
5 
6 // The class responsible for tx interpreting/parsing.
7 //
8 // It invokes other classes & methods: offers, accepts, tallies (balances).
10 {
11 private:
12  string sender;
13  string receiver;
15  int block;
16  unsigned int tx_idx; // tx # within the block, 0-based
17  int pkt_size;
18  unsigned char pkt[1 + MAX_PACKETS * PACKET_SIZE];
19  uint64_t nValue;
20  int multi; // Class A = 0, Class B = 1
21  uint64_t tx_fee_paid;
22  unsigned int type;
23  unsigned int property;
24  unsigned short version; // = MP_TX_PKT_V0;
25  uint64_t nNewValue;
26  int64_t blockTime; // internally nTime is still an "unsigned int"
27 
28 // SP additions, perhaps a new class or a union is needed
29  unsigned char ecosystem;
30  unsigned short prop_type;
31  unsigned int prev_prop_id;
32 
38 
39  uint64_t deadline;
40  unsigned char early_bird;
41  unsigned char percentage;
42 
43  // METADEX additions
44  unsigned int desired_property;
45  uint64_t desired_value;
46 
48  {
49  public:
50 
51  bool operator()(pair<int64_t, string> p1, pair<int64_t, string> p2) const
52  {
53  if (p1.first == p2.first) return p1.second > p2.second; // reverse check
54  else return p1.first < p2.first;
55  }
56  };
57 
58 public:
60  {
61  INVALID = 0,
62 
63  NEW = 1,
64 
65  UPDATE = 2,
66 
67  CANCEL = 3,
68 
69  ADD = 1,
73  };
74 
75 // mutable CCriticalSection cs_msc; // TODO: need to refactor first...
76 
77  unsigned int getType() const { return type; }
78  const string getTypeString() const { return string(c_strMasterProtocolTXType(getType())); }
79  unsigned int getProperty() const { return property; }
80  unsigned short getVersion() const { return version; }
81  unsigned short getPropertyType() const { return prop_type; }
82  uint64_t getFeePaid() const { return tx_fee_paid; }
83 
84  const string & getSender() const { return sender; }
85  const string & getReceiver() const { return receiver; }
86 
87  uint64_t getAmount() const { return nValue; }
88  uint64_t getNewAmount() const { return nNewValue; }
89 
90  string getSPName() const { return string(name); }
91 
92  void printInfo(FILE *fp);
93 
94  void SetNull()
95  {
96  property = 0;
97  type = 0;
98  txid = 0;
99  tx_idx = 0; // tx # within the block, 0-based
100  nValue = 0;
101  nNewValue = 0;
102  tx_fee_paid = 0;
103  block = -1;
104  pkt_size = 0;
105  sender.erase();
106  receiver.erase();
107 
108  blockTime = 0;
109 
110  ecosystem = 0;
111  prop_type = 0;
112  prev_prop_id = 0;
113 
114  memset(&pkt, 0, sizeof(pkt));
115 
116  memset(&category, 0, sizeof(category));
117  memset(&subcategory, 0, sizeof(subcategory));
118  memset(&name, 0, sizeof(name));
119  memset(&url, 0, sizeof(url));
120  memset(&data, 0, sizeof(data));
121  }
122 
124  {
125  SetNull();
126  }
127 
128  int logicMath_SimpleSend(void);
130  int logicMath_AcceptOffer_BTC(void);
131  int logicMath_SendToOwners(FILE *fp = NULL);
133  int logicMath_GrantTokens(void);
134  int logicMath_RevokeTokens(void);
135  int logicMath_ChangeIssuer(void);
136  int logicMath_SavingsMark(void);
138 
139  int interpretPacket(CMPOffer *obj_o = NULL, CMPMetaDEx *mdex_o = NULL);
140  int step1(void);
141  int step2_Alert(std::string *new_global_alert_message);
142  int step2_Value(void);
143  bool isOverrun(const char *p, unsigned int line);
144  const char *step2_SmartProperty(int &error_code);
145  int step3_sp_fixed(const char *p);
146  int step3_sp_variable(const char *p);
147 
148  void Set(const uint256 &t, int b, unsigned int idx, int64_t bt)
149  {
150  txid = t;
151  block = b;
152  tx_idx = idx;
153  blockTime = bt;
154  }
155 
156  void Set(string s, string r, uint64_t n, const uint256 &t, int b, unsigned int idx, unsigned char *p, unsigned int size, int fMultisig, uint64_t txf)
157  {
158  sender = s;
159  receiver = r;
160  txid = t;
161  block = b;
162  tx_idx = idx;
163  pkt_size = size < sizeof(pkt) ? size : sizeof(pkt);
164  nValue = n;
165  nNewValue = n;
166  multi= fMultisig;
167  tx_fee_paid = txf;
168 
169  memcpy(&pkt, p, pkt_size);
170  }
171 
172  bool operator<(const CMPTransaction& other) const
173  {
174  // sort by block # & additionally the tx index within the block
175  if (block != other.block) return block > other.block;
176  return tx_idx > other.tx_idx;
177  }
178 
179  void print()
180  {
181  file_log("BLOCK: %d =txid: %s =fee: %1.8lf\n", block, txid.GetHex(), (double)tx_fee_paid/(double)COIN);
182  file_log("sender: %s ; receiver: %s\n", sender, receiver);
183 
184  if (0<pkt_size)
185  {
186  file_log("pkt: %s\n", HexStr(pkt, pkt_size + pkt, false));
187  }
188  else
189  {
190  // error ?
191  }
192  }
193 };
194 
195 int parseTransaction(bool bRPConly, const CTransaction &wtx, int nBlock, unsigned int idx, CMPTransaction *mp_tx, unsigned int nTime=0);
196 
197 #endif // #ifndef _MASTERCOIN_TX
198 
const string & getSender() const
Definition: mastercore_tx.h:84
unsigned char early_bird
Definition: mastercore_tx.h:40
int logicMath_RevokeTokens(void)
#define MAX_PACKETS
Definition: mastercore.h:51
void Set(const uint256 &t, int b, unsigned int idx, int64_t bt)
unsigned char percentage
Definition: mastercore_tx.h:41
unsigned int type
Definition: mastercore_tx.h:22
uint64_t getFeePaid() const
Definition: mastercore_tx.h:82
int logicMath_SimpleSend(void)
const string & getReceiver() const
Definition: mastercore_tx.h:85
int logicMath_GrantTokens(void)
unsigned int desired_property
Definition: mastercore_tx.h:44
string getSPName() const
Definition: mastercore_tx.h:90
bool isOverrun(const char *p, unsigned int line)
int parseTransaction(bool bRPConly, const CTransaction &wtx, int nBlock, unsigned int idx, CMPTransaction *mp_tx, unsigned int nTime=0)
unsigned int getProperty() const
Definition: mastercore_tx.h:79
char data[SP_STRING_FIELD_LEN]
Definition: mastercore_tx.h:37
uint64_t nNewValue
Definition: mastercore_tx.h:25
char category[SP_STRING_FIELD_LEN]
Definition: mastercore_tx.h:33
char * c_strMasterProtocolTXType(int i)
const char * step2_SmartProperty(int &error_code)
int step2_Alert(std::string *new_global_alert_message)
int logicMath_SavingsCompromised(void)
#define SP_STRING_FIELD_LEN
Definition: mastercore.h:31
unsigned short getPropertyType() const
Definition: mastercore_tx.h:81
char name[SP_STRING_FIELD_LEN]
Definition: mastercore_tx.h:35
unsigned short prop_type
Definition: mastercore_tx.h:30
unsigned char ecosystem
Definition: mastercore_tx.h:29
unsigned short getVersion() const
Definition: mastercore_tx.h:80
uint64_t getNewAmount() const
Definition: mastercore_tx.h:88
unsigned short version
Definition: mastercore_tx.h:24
int step3_sp_fixed(const char *p)
std::string GetHex() const
Definition: uint256.h:297
int logicMath_ChangeIssuer(void)
uint64_t nValue
Definition: mastercore_tx.h:19
int logicMath_SavingsMark(void)
uint64_t desired_value
Definition: mastercore_tx.h:45
int logicMath_TradeOffer(CMPOffer *)
256-bit unsigned integer
Definition: uint256.h:531
static const int64_t COIN
Definition: util.h:38
uint64_t getAmount() const
Definition: mastercore_tx.h:87
void printInfo(FILE *fp)
int step2_Value(void)
int logicMath_AcceptOffer_BTC(void)
#define PACKET_SIZE
Definition: mastercore.h:50
void * memcpy(void *a, const void *b, size_t c)
Definition: glibc_compat.cpp:7
unsigned char pkt[1+MAX_PACKETS *PACKET_SIZE]
Definition: mastercore_tx.h:18
uint64_t tx_fee_paid
Definition: mastercore_tx.h:21
int step3_sp_variable(const char *p)
char url[SP_STRING_FIELD_LEN]
Definition: mastercore_tx.h:36
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: core.h:183
int64_t blockTime
Definition: mastercore_tx.h:26
const string getTypeString() const
Definition: mastercore_tx.h:78
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: util.h:263
bool operator<(const CMPTransaction &other) const
bool operator()(pair< int64_t, string > p1, pair< int64_t, string > p2) const
Definition: mastercore_tx.h:51
char subcategory[SP_STRING_FIELD_LEN]
Definition: mastercore_tx.h:34
unsigned int prev_prop_id
Definition: mastercore_tx.h:31
int interpretPacket(CMPOffer *obj_o=NULL, CMPMetaDEx *mdex_o=NULL)
unsigned int property
Definition: mastercore_tx.h:23
unsigned int tx_idx
Definition: mastercore_tx.h:16
uint64_t deadline
Definition: mastercore_tx.h:39
int logicMath_SendToOwners(FILE *fp=NULL)
unsigned int getType() const
Definition: mastercore_tx.h:77
void Set(string s, string r, uint64_t n, const uint256 &t, int b, unsigned int idx, unsigned char *p, unsigned int size, int fMultisig, uint64_t txf)
int logicMath_MetaDEx(CMPMetaDEx *)