2 #define _MASTERCOIN_SP 1
76 spInfo.push_back(Pair(
"issuer", issuer));
77 spInfo.push_back(Pair(
"prop_type", prop_type));
78 spInfo.push_back(Pair(
"prev_prop_id", (uint64_t)prev_prop_id));
79 spInfo.push_back(Pair(
"category", category));
80 spInfo.push_back(Pair(
"subcategory", subcategory));
81 spInfo.push_back(Pair(
"name", name));
82 spInfo.push_back(Pair(
"url", url));
83 spInfo.push_back(Pair(
"data", data));
84 spInfo.push_back(Pair(
"fixed", fixed));
85 spInfo.push_back(Pair(
"manual", manual));
87 spInfo.push_back(Pair(
"num_tokens", (
boost::format(
"%d") % num_tokens).str()));
88 if (
false == fixed &&
false == manual) {
89 spInfo.push_back(Pair(
"property_desired", (uint64_t)property_desired));
90 spInfo.push_back(Pair(
"deadline", (
boost::format(
"%d") % deadline).str()));
91 spInfo.push_back(Pair(
"early_bird", (
int)early_bird));
92 spInfo.push_back(Pair(
"percentage", (
int)percentage));
94 spInfo.push_back(Pair(
"close_early", (
int)close_early));
95 spInfo.push_back(Pair(
"max_tokens", (
int)max_tokens));
96 spInfo.push_back(Pair(
"missedTokens", (
int) missedTokens));
97 spInfo.push_back(Pair(
"timeclosed", (
boost::format(
"%d") % timeclosed).str()));
102 std::map<std::string, std::vector<uint64_t> >::const_iterator it;
104 std::string values_long =
"";
105 std::string values =
"";
110 bool crowdsale = !fixed && !
manual;
111 for(it = historicalData.begin(); it != historicalData.end(); it++) {
112 values += it->first.c_str();
114 values +=
":" + boost::lexical_cast<std::string>(it->second.at(0));
115 values +=
":" + boost::lexical_cast<std::string>(it->second.at(1));
116 values +=
":" + boost::lexical_cast<std::string>(it->second.at(2));
117 values +=
":" + boost::lexical_cast<std::string>(it->second.at(3));
119 values +=
":" + boost::lexical_cast<std::string>(it->second.at(0));
120 values +=
":" + boost::lexical_cast<std::string>(it->second.at(1));
123 values_long += values;
127 spInfo.push_back(Pair(
"historicalData", values_long));
136 unsigned int idx = 0;
137 issuer = json[idx++].value_.get_str();
138 prop_type = (
unsigned short)json[idx++].value_.get_int();
139 prev_prop_id = (
unsigned int)json[idx++].value_.get_uint64();
140 category = json[idx++].value_.get_str();
141 subcategory = json[idx++].value_.get_str();
142 name = json[idx++].value_.get_str();
143 url = json[idx++].value_.get_str();
144 data = json[idx++].value_.get_str();
145 fixed = json[idx++].value_.get_bool();
146 manual = json[idx++].value_.get_bool();
148 num_tokens = boost::lexical_cast<uint64_t>(json[idx++].value_.get_str());
149 if (
false == fixed &&
false == manual) {
150 property_desired = (
unsigned int)json[idx++].value_.get_uint64();
151 deadline = boost::lexical_cast<uint64_t>(json[idx++].value_.get_str());
152 early_bird = (
unsigned char)json[idx++].value_.get_int();
153 percentage = (
unsigned char)json[idx++].value_.get_int();
155 close_early = (
unsigned char)json[idx++].value_.get_int();
156 max_tokens = (
unsigned char)json[idx++].value_.get_int();
157 missedTokens = (
unsigned char)json[idx++].value_.get_int();
158 timeclosed = boost::lexical_cast<uint64_t>(json[idx++].value_.get_str());
159 txid_close =
uint256(json[idx++].value_.get_str());
163 std::string longstr = json[idx++].value_.get_str();
167 std::vector<std::string> strngs_vec;
170 boost::split(strngs_vec, longstr, boost::is_any_of(
";"));
175 bool crowdsale = !fixed && !
manual;
176 for(std::vector<std::string>::size_type i = 0; i != strngs_vec.size(); i++) {
177 if (strngs_vec[i].empty()) {
181 std::vector<std::string> str_split_vec;
182 boost::split(str_split_vec, strngs_vec[i], boost::is_any_of(
":"));
184 std::vector<uint64_t> txDataVec;
186 if ( crowdsale && str_split_vec.size() == 5) {
188 txDataVec.push_back(boost::lexical_cast<uint64_t>( str_split_vec.at(1) ));
189 txDataVec.push_back(boost::lexical_cast<uint64_t>( str_split_vec.at(2) ));
190 txDataVec.push_back(boost::lexical_cast<uint64_t>( str_split_vec.at(3) ));
191 txDataVec.push_back(boost::lexical_cast<uint64_t>( str_split_vec.at(4) ));
192 }
else if (manual && str_split_vec.size() == 3) {
193 txDataVec.push_back(boost::lexical_cast<uint64_t>( str_split_vec.at(1) ));
194 txDataVec.push_back(boost::lexical_cast<uint64_t>( str_split_vec.at(2) ));
197 historicalData.insert(std::make_pair( str_split_vec.at(0), txDataVec ) ) ;
200 txid =
uint256(json[idx++].value_.get_str());
201 creation_block =
uint256(json[idx++].value_.get_str());
202 update_block =
uint256(json[idx++].value_.get_str());
219 printf(
"%s:%s(Fixed=%s,Divisible=%s):%lu:%s/%s, %s %s\n",
225 category.c_str(), subcategory.c_str(), url.c_str(), data.c_str());
232 boost::filesystem::path
const path;
242 leveldb::Options options;
243 options.paranoid_checks =
true;
244 options.create_if_missing =
true;
246 leveldb::Status s = leveldb::DB::Open(options, path.string(), &
pDb);
248 if (
false == s.ok()) {
249 printf(
"Failed to create or read LevelDB for Smart Property at %s", path.c_str());
271 implied_msc.
name =
"MasterCoin";
272 implied_msc.
url =
"www.mastercoin.org";
273 implied_msc.
data =
"***data***";
279 implied_tmsc.
name =
"Test MasterCoin";
280 implied_tmsc.
url =
"www.mastercoin.org";
281 implied_tmsc.
data =
"***data***";
293 next_spid = nextSPID;
294 next_test_spid = nextTestSPID;
299 leveldb::DestroyDB(path.string(), leveldb::Options());
306 unsigned int nextId = 0;
322 unsigned int updateSP(
unsigned int propertyID, Entry
const &info);
323 unsigned int putSP(
unsigned char ecosystem, Entry
const &info);
324 bool getSP(
unsigned int spid, Entry &info);
325 bool hasSP(
unsigned int spid);
334 leveldb::WriteOptions writeOptions;
335 writeOptions.sync =
true;
337 leveldb::WriteBatch commitBatch;
338 commitBatch.Delete(watermarkKey);
339 commitBatch.Put(watermarkKey, watermark.
ToString());
340 pDb->Write(writeOptions, &commitBatch);
345 leveldb::ReadOptions readOpts;
346 readOpts.fill_cache =
false;
348 if (pDb->Get(readOpts, watermarkKey, &watermarkVal).ok()) {
349 watermark.
SetHex(watermarkVal);
361 printf(
"%10d => ", idx);
362 if (
getSP(idx, info)) {
365 printf(
"<Internal Error on implicit SP>\n");
369 leveldb::ReadOptions readOpts;
370 readOpts.fill_cache =
false;
371 leveldb::Iterator *iter = pDb->NewIterator(readOpts);
372 for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
373 if (iter->key().starts_with(
"sp-")) {
374 std::vector<std::string> vstr;
375 std::string key = iter->key().ToString();
376 boost::split(vstr, key, boost::is_any_of(
"-"), token_compress_on);
378 printf(
"%10s => ", vstr[1].c_str());
382 if (read_string(iter->value().ToString(), spInfoVal) && spInfoVal.type() == obj_type ) {
387 printf(
"<Malformed JSON in DB>\n");
417 CMPCrowd():propertyId(0),nValue(0),property_desired(0),deadline(0),early_bird(0),percentage(0),u_created(0),i_created(0)
421 CMPCrowd(
unsigned int pid, uint64_t nv,
unsigned int cd, uint64_t dl,
unsigned char eb,
unsigned char per, uint64_t uct, uint64_t ict):
422 propertyId(pid),nValue(nv),property_desired(cd),deadline(dl),early_bird(eb),percentage(per),u_created(uct),i_created(ict)
437 void insertDatabase(std::string txhash, std::vector<uint64_t> txdata ) { txFundraiserData.insert(std::make_pair<std::string, std::vector<uint64_t>& >(txhash,txdata)); }
440 void print(
const string & address, FILE *fp = stdout)
const
442 fprintf(fp,
"%34s : id=%u=%X; prop=%u, value= %lu, deadline: %s (%lX)\n", address.c_str(),
propertyId,
propertyId,
446 void saveCrowdSale(ofstream &file, SHA256_CTX *shaCtx,
string const &addr)
const
450 string lineOut = (
boost::format(
"%s,%d,%d,%d,%d,%d,%d,%d,%d")
462 std::map<std::string, std::vector<uint64_t> >::const_iterator iter;
463 for (iter = txFundraiserData.begin(); iter != txFundraiserData.end(); ++iter) {
464 lineOut.append((
boost::format(
",%s=") % (*iter).first).str());
465 std::vector<uint64_t>
const &vals = (*iter).second;
467 std::vector<uint64_t>::const_iterator valIter;
468 for (valIter = vals.begin(); valIter != vals.end(); ++valIter) {
469 if (valIter != vals.begin()) {
478 SHA256_Update(shaCtx, lineOut.c_str(), lineOut.length());
481 file << lineOut << endl;
497 int calculateFractional(
unsigned short int propType,
unsigned char bonusPerc, uint64_t fundraiserSecs,
498 uint64_t numProps,
unsigned char issuerPerc,
const std::map<std::string, std::vector<uint64_t> > txFundraiserData,
499 const uint64_t amountPremined );
508 #endif // _MASTERCOIN_SP
int popBlock(uint256 const &block_hash)
void SetHex(const char *psz)
#define MSC_PROPERTY_TYPE_DIVISIBLE_REPLACING
std::map< std::string, std::vector< uint64_t > > txFundraiserData
boost::filesystem::path const path
#define MSC_PROPERTY_TYPE_DIVISIBLE_APPENDING
void init(unsigned int nextSPID=0x3UL, unsigned int nextTestSPID=TEST_ECO_PROPERTY_1)
uint64_t getCurrDes() const
uint64_t getUserCreated() const
CMPCrowd(unsigned int pid, uint64_t nv, unsigned int cd, uint64_t dl, unsigned char eb, unsigned char per, uint64_t uct, uint64_t ict)
void saveCrowdSale(ofstream &file, SHA256_CTX *shaCtx, string const &addr) const
#define TEST_ECO_PROPERTY_1
bool hasSP(unsigned int spid)
std::map< std::string, std::vector< uint64_t > > getDatabase() const
void print(const string &address, FILE *fp=stdout) const
std::string DateTimeStrFormat(const char *pszFormat, int64_t nTime)
std::map< string, CMPCrowd > CrowdMap
#define OMNI_PROPERTY_MSC
unsigned int property_desired
std::map< std::string, std::vector< uint64_t > > historicalData
int calculateFractional(unsigned short int propType, unsigned char bonusPerc, uint64_t fundraiserSecs, uint64_t numProps, unsigned char issuerPerc, const std::map< std::string, std::vector< uint64_t > > txFundraiserData, const uint64_t amountPremined)
#define OMNI_PROPERTY_TMSC
uint64_t getIssuerCreated() const
void dumpCrowdsaleInfo(const string &address, CMPCrowd &crowd, bool bExpired=false)
unsigned int property_desired
unsigned int next_test_spid
void fromJSON(Object const &json)
bool getSP(unsigned int spid, Entry &info)
#define MSC_PROPERTY_TYPE_DIVISIBLE
unsigned int prev_prop_id
void eraseMaxedCrowdsale(const string &address, uint64_t blockTime, int block)
void insertDatabase(std::string txhash, std::vector< uint64_t > txdata)
void setWatermark(uint256 const &watermark)
unsigned int putSP(unsigned char ecosystem, Entry const &info)
char * c_strPropertyType(int i)
The block chain is a tree shaped structure starting with the genesis block at the root...
std::string ToString() const
const std::string ExodusAddress()
unsigned int findSPByTX(uint256 const &txid)
int getWatermark(uint256 &watermark)
unsigned int peekNextSPID(unsigned char ecosystem)
void incTokensUserCreated(uint64_t amount)
static string const watermarkKey
CMPCrowd * getCrowd(const string &address)
CMPSPInfo(const boost::filesystem::path &_path)
void incTokensIssuerCreated(uint64_t amount)
unsigned int eraseExpiredCrowdsale(CBlockIndex const *pBlockIndex)
uint64_t getDeadline() const
unsigned int updateSP(unsigned int propertyID, Entry const &info)
unsigned int getPropertyId() const