Skip to content

Commit

Permalink
Merge pull request #9 from MythicalGames/cdt-update
Browse files Browse the repository at this point in the history
PLAT-105 update to latest cdt, bug fixes
  • Loading branch information
cthacker authored Jun 5, 2019
2 parents 828b3e6 + 25ede89 commit 1ad6cd0
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 119 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.PHONY: clean
clean:
rm -rf build

.PHONY: build
build:
mkdir -p build
cd build && cmake ../ && make
mv build/dgoods/dgoods* .
rm -rf build/*
mkdir -p build/dgoods
mv dgoods.abi dgoods.wasm build/dgoods/
30 changes: 5 additions & 25 deletions build/dgoods/dgoods.abi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT Mon May 6 16:40:44 2019",
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
"version": "eosio::abi/1.1",
"types": [],
"structs": [
{
"name": "accounts",
Expand Down Expand Up @@ -201,7 +202,7 @@
"type": "name"
},
{
"name": "metadata_uri",
"name": "relative_uri",
"type": "string?"
}
]
Expand Down Expand Up @@ -273,7 +274,7 @@
"type": "string"
},
{
"name": "metadata_uri",
"name": "relative_uri",
"type": "string"
},
{
Expand Down Expand Up @@ -324,20 +325,6 @@
}
]
},
{
"name": "setrampayer",
"base": "",
"fields": [
{
"name": "payer",
"type": "name"
},
{
"name": "id",
"type": "uint64"
}
]
},
{
"name": "tokenconfigs",
"base": "",
Expand Down Expand Up @@ -413,7 +400,6 @@
]
}
],
"types": [],
"actions": [
{
"name": "burnft",
Expand Down Expand Up @@ -460,11 +446,6 @@
"type": "setconfig",
"ricardian_contract": ""
},
{
"name": "setrampayer",
"type": "setrampayer",
"ricardian_contract": ""
},
{
"name": "transferft",
"type": "transferft",
Expand Down Expand Up @@ -521,6 +502,5 @@
}
],
"ricardian_clauses": [],
"variants": [],
"abi_extensions": []
"variants": []
}
Binary file modified build/dgoods/dgoods.wasm
Binary file not shown.
12 changes: 7 additions & 5 deletions include/dasset.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <eosiolib/eosio.hpp>
#include <string>
#include "utility.hpp"

Expand All @@ -23,25 +22,25 @@ namespace dgoods_asset {

void _check_precision(const uint8_t& p) {
static constexpr uint8_t max_precision = 18;
eosio_assert( p <= max_precision, "precision must be less than 19");
check( p <= max_precision, "precision must be less than 19");
}

void _check_max(const uint64_t& a) {
static constexpr uint64_t max_amount = ( 1LL << 62 ) - 1;
eosio_assert( a <= max_amount, "max supply must be less than 2^62 - 1");
eosio_assert( a > 0, "max supply must be greater than 0");
check( a < max_amount, "max supply must be less than 2^62 - 1");
}

dasset() {}

void from_string(const string& s) {
string string_amount = trim(s);
check( ( string_amount[0] != '-' ), "Amount can not be negative" );
auto dot_pos = string_amount.find('.');
uint64_t uint_part;
uint64_t frac_part;
uint64_t p10;
if ( dot_pos != string::npos ) {
eosio_assert( ( dot_pos != string_amount.size() - 1 ), "missing decimal fraction after decimal point");
check( ( dot_pos != string_amount.size() - 1 ), "missing decimal fraction after decimal point");
}
if ( dot_pos == string::npos ) {
uint_part = stoull(string_amount);
Expand All @@ -57,6 +56,7 @@ namespace dgoods_asset {
frac_part = stoull(string_amount.substr( dot_pos + 1 ));
}
amount = uint_part * p10 + frac_part;
check( amount > 0, "max supply must be greater than 0");

}

Expand All @@ -66,6 +66,7 @@ namespace dgoods_asset {
_check_precision(p);

string string_amount = trim(s);
check( ( string_amount[0] != '-' ), "Amount can not be negative" );
// 1.0 1. 1
uint64_t uint_part;
uint64_t frac_part;
Expand All @@ -82,6 +83,7 @@ namespace dgoods_asset {
_check_max(uint_part);
uint64_t p10 = _get_precision(p);
amount = uint_part * p10 + frac_part;
check( amount > 0, "max supply must be greater than 0");

}

Expand Down
25 changes: 11 additions & 14 deletions include/dgoods.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include <eosiolib/asset.hpp>
#include <eosiolib/symbol.hpp>
#include <eosiolib/eosio.hpp>
#include <eosiolib/time.hpp>
#include <eosiolib/singleton.hpp>
#include <eosio/asset.hpp>
#include <eosio/symbol.hpp>
#include <eosio/eosio.hpp>
#include <eosio/time.hpp>
#include <eosio/singleton.hpp>
#include <string>
#include <vector>

Expand Down Expand Up @@ -52,15 +52,12 @@ CONTRACT dgoods: public contract {

ACTION buynft(name from, name to, asset quantity, string memo);

ACTION setrampayer(name payer,
uint64_t id);

ACTION transfernft(name from,
name to,
vector<uint64_t> dgood_ids,
string memo);

ACTION transferft(name from,
ACTION transferft(name from,
name to,
name category,
name token_name,
Expand Down Expand Up @@ -160,9 +157,9 @@ CONTRACT dgoods: public contract {

private:

void mint( name to, name issuer, name category, name token_name,
uint64_t issued_supply, string relative_uri );
void add_balance( name owner, name issuer, name category, name token_name,
uint64_t category_name_id, dasset quantity );
void sub_balance( name owner, uint64_t category_name_id, dasset quantity );
void mint(name to, name issuer, name category, name token_name,
uint64_t issued_supply, string relative_uri);
void add_balance(name owner, name issuer, name category, name token_name,
uint64_t category_name_id, dasset quantity);
void sub_balance(name owner, uint64_t category_name_id, dasset quantity);
};
8 changes: 5 additions & 3 deletions include/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <algorithm>
#include <cctype>
#include <locale>
#include <eosiolib/eosio.hpp>
#include <eosio/eosio.hpp>

using namespace std;
using namespace eosio;
Expand Down Expand Up @@ -34,10 +34,12 @@ namespace utility {

tuple<uint64_t, name> parsememo(const string& memo) {
auto dot_pos = memo.find(',');
string errormsg = "malformed memo: must have dgood_id,to_account";
check ( dot_pos != string::npos, errormsg.c_str() );
if ( dot_pos != string::npos ) {
eosio_assert( ( dot_pos != memo.size() - 1 ), "malformed memo, must have dgood_id,to_account");
check( ( dot_pos != memo.size() - 1 ), errormsg.c_str() );
}
// need to trim substring
// will abort if stoull throws error since wasm no error checking
uint64_t dgood_id = stoull( trim( memo.substr( 0, dot_pos ) ) );
name to_account = name( trim ( memo.substr( dot_pos + 1 ) ) );

Expand Down
Loading

0 comments on commit 1ad6cd0

Please sign in to comment.