Skip to content

Commit

Permalink
Add total supply field to fungibles table in postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
harrywong committed Dec 15, 2018
1 parent 62de10f commit 7298110
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions plugins/postgres_plugin/evt_pg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

namespace evt {

// Update:
// - 1.1.0: add `global_seq` field to `actions` table
// - 1.2.0: add `trx_id` feild to `metas`, `domains`, `tokens`, `groups` and `fungibles` tables
/*
* Update:
* - 1.1.0: add `global_seq` field to `actions` table
* - 1.2.0: add `trx_id` feild to `metas`, `domains`, `tokens`, `groups` and `fungibles` tables
* add `total_supply` field to `fungibles` table
*/
static auto pg_version = "1.2.0";

namespace __internal {
Expand Down Expand Up @@ -72,18 +75,14 @@ auto create_blocks_table = R"sql(CREATE TABLE IF NOT EXISTS public.blocks
trx_count integer NOT NULL,
producer character varying(21) NOT NULL,
pending boolean NOT NULL DEFAULT true,
created_at timestamp with time zone NOT NULL DEFAULT now()
created_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT blocks_pkey PRIMARY KEY (block_id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
CREATE INDEX IF NOT EXISTS blocks_block_id_index
ON public.blocks USING btree
(block_id)
TABLESPACE pg_default;
CREATE INDEX IF NOT EXISTS blocks_block_num_index
ON public.blocks USING btree
(block_num)
Expand All @@ -108,7 +107,8 @@ auto create_trxs_table = R"sql(CREATE TABLE IF NOT EXISTS public.transactions
elapsed integer NOT NULL,
charge integer NOT NULL,
suspend_name character varying(21),
created_at timestamp with time zone NOT NULL DEFAULT now()
created_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT transactions_pkey PRIMARY KEY (trx_id)
)
WITH (
OIDS = FALSE
Expand Down Expand Up @@ -223,17 +223,18 @@ auto create_groups_table = R"sql(CREATE TABLE IF NOT EXISTS public.groups

auto create_fungibles_table = R"sql(CREATE TABLE IF NOT EXISTS public.fungibles
(
name character varying(21) NOT NULL,
sym_name character varying(21) NOT NULL,
sym character varying(21) NOT NULL,
sym_id bigint NOT NULL,
creator character(53) NOT NULL,
issue jsonb NOT NULL,
manage jsonb NOT NULL,
metas integer[] NOT NULL,
trx_id character(64) NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT fungibles_pkey PRIMARY KEY (sym_id)
name character varying(21) NOT NULL,
sym_name character varying(21) NOT NULL,
sym character varying(21) NOT NULL,
sym_id bigint NOT NULL,
creator character(53) NOT NULL,
issue jsonb NOT NULL,
manage jsonb NOT NULL,
total_supply character varying(32) NOT NULL,
metas integer[] NOT NULL,
trx_id character(64) NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT fungibles_pkey PRIMARY KEY (sym_id)
)
WITH (
OIDS = FALSE
Expand Down Expand Up @@ -839,7 +840,7 @@ pg::upd_group(trx_context& tctx, const updategroup& ug) {
return PG_OK;
}

PREPARE_SQL_ONCE(nf_plan, "INSERT INTO fungibles VALUES($1, $2, $3, $4, $5, $6, $7, '{}', $8, now());");
PREPARE_SQL_ONCE(nf_plan, "INSERT INTO fungibles VALUES($1, $2, $3, $4, $5, $6, $7, $8, '{}', $9, now());");

int
pg::add_fungible(trx_context& tctx, const newfungible& nf) {
Expand All @@ -848,14 +849,15 @@ pg::add_fungible(trx_context& tctx, const newfungible& nf) {
fc::to_variant(nf.manage, manage);

fmt::format_to(tctx.trx_buf_,
fmt("EXECUTE nf_plan('{}','{}','{}',{:d},'{}','{}','{}','{}');\n"),
fmt("EXECUTE nf_plan('{}','{}','{}',{:d},'{}','{}','{}','{}','{}');\n"),
(std::string)nf.name,
(std::string)nf.sym_name,
(std::string)nf.sym,
(int64_t)nf.sym.id(),
(std::string)nf.creator,
fc::json::to_string(issue),
fc::json::to_string(manage),
nf.total_supply.to_string(),
tctx.trx_id()
);

Expand Down

0 comments on commit 7298110

Please sign in to comment.