Skip to content

Commit

Permalink
Save wallet properties for ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Feb 6, 2019
1 parent bee7014 commit 3289ada
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
79 changes: 79 additions & 0 deletions vendor/bat-native-ledger/src/bat_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,56 @@ static bool ignore_ = false;
return !error;
}

void saveToJson(JsonWriter & writer, const WALLET_PROPERTIES_ST& data) {
writer.StartObject();

writer.String("altcurrency");
writer.String(data.altcurrency_.c_str());

writer.String("probi_");
writer.String(data.probi_.c_str());

writer.String("balance");
writer.Double(data.balance_);

writer.String("fee_amount");
writer.Double(data.fee_amount_);

writer.String("rates");
writer.StartObject();
for (auto & p : data.rates_) {
writer.String(p.first.c_str());
writer.Double(p.second);
}
writer.EndObject();

writer.String("parameters_choices");
writer.StartArray();
for (auto & choice : data.parameters_choices_) {
writer.Double(choice);
}
writer.EndArray();

writer.String("parameters_range");
writer.StartArray();
for (auto & choice : data.parameters_range_) {
writer.Double(choice);
}
writer.EndArray();

writer.String("parameters_days");
writer.Int(data.parameters_days_);

writer.String("grants");
writer.StartArray();
for (auto & grant : data.grants_) {
saveToJson(writer, grant);
}
writer.EndArray();

writer.EndObject();
}

/////////////////////////////////////////////////////////////////////////////
GRANT::GRANT() : expiryTime(0) {}

Expand Down Expand Up @@ -944,6 +994,24 @@ static bool ignore_ = false;
return !error;
}

void saveToJson(JsonWriter & writer, const GRANT& data) {
writer.StartObject();

writer.String("altcurrency");
writer.String(data.altcurrency.c_str());

writer.String("probi");
writer.String(data.probi.c_str());

writer.String("expiryTime");
writer.Uint64(data.expiryTime);

writer.String("promotionId");
writer.String(data.promotionId.c_str());

writer.EndObject();
}

/////////////////////////////////////////////////////////////////////////////
SURVEYOR_INFO_ST::SURVEYOR_INFO_ST() {}

Expand Down Expand Up @@ -1386,6 +1454,14 @@ static bool ignore_ = false;
current_reconciles_[i.name.GetString()] = b;
}
}

if (d.HasMember("walletProperties") && d["walletProperties"].IsObject()) {
auto & i = d["walletProperties"];
rapidjson::StringBuffer sb;
rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
i.Accept(writer);
walletProperties_.loadFromJson(sb.GetString());
}
}

return !error;
Expand Down Expand Up @@ -1477,6 +1553,9 @@ static bool ignore_ = false;
}
writer.EndObject();

writer.String("walletProperties");
saveToJson(writer, data.walletProperties_);

writer.EndObject();
}

Expand Down
2 changes: 2 additions & 0 deletions vendor/bat-native-ledger/src/rapidjson_bat_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void saveToJson(JsonWriter & writer, const ledger::WalletInfo&);
void saveToJson(JsonWriter & writer, const ledger::PendingContribution&);
void saveToJson(JsonWriter & writer, const ledger::PendingContributionList&);
void saveToJson(JsonWriter & writer, const ledger::PublisherInfoListStruct&);
void saveToJson(JsonWriter & writer, const WALLET_PROPERTIES_ST&);
void saveToJson(JsonWriter & writer, const GRANT&);

template <typename T>
void saveToJsonString(const T& t, std::string& json) {
Expand Down

0 comments on commit 3289ada

Please sign in to comment.