Skip to content
Snippets Groups Projects
Commit c017ec12 authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

Support for defining transaction types

parent 2b1c2651
No related branches found
No related tags found
No related merge requests found
FROM debian FROM debian
RUN useradd --create-home --shell /bin/bash bfa && mkdir /home/bfa/collector RUN useradd --create-home --shell /bin/bash bfa && mkdir /home/bfa/collector
RUN apt-get update && apt-get upgrade -y RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y libjson-perl libnet-dns-perl libdbd-pg-perl libwww-perl vim RUN apt-get install -y libjson-perl libnet-dns-perl libdbd-pg-perl libwww-perl libclass-accessor-perl
RUN apt-get install -y libclass-accessor-perl WORKDIR /home/bfa
COPY collector.pl sql.pm /home/bfa/collector/ COPY collector.pl sql.pm /home/bfa/collector/
RUN chown -R bfa /home/bfa RUN chown -R bfa /home/bfa
USER bfa USER bfa
WORKDIR /home/bfa
ENV BFANODE http://public.47525974938.bfa.martin-legene.dk:8545/
CMD /home/bfa/collector/collector.pl CMD /home/bfa/collector/collector.pl
#CMD sleep 14d #CMD sleep 14d
ENV BFANODE http://public.47525974938.bfa.martin-legene.dk:8545/
...@@ -62,8 +62,8 @@ sub insertTransactionWithContractAddress ...@@ -62,8 +62,8 @@ sub insertTransactionWithContractAddress
( hash, "blockId", nonce, gas, ( hash, "blockId", nonce, gas,
"gasPrice", value, "fromAccountId","toAccountId", "gasPrice", value, "fromAccountId","toAccountId",
status, "gasUsed", input, inputlen, status, "gasUsed", input, inputlen,
"contractaddressAccountId" ) "type", "contractaddressAccountId" )
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
)) ))
); );
} }
...@@ -71,7 +71,7 @@ sub insertTransactionWithContractAddress ...@@ -71,7 +71,7 @@ sub insertTransactionWithContractAddress
$_[6] = $self->selectAccountIdByAddress( $_[6] ); $_[6] = $self->selectAccountIdByAddress( $_[6] );
$_[7] = $self->selectAccountIdByAddress( $_[7] ); $_[7] = $self->selectAccountIdByAddress( $_[7] );
$_[12] = $self->selectAccountIdByAddress( $_[12] ); $_[12] = $self->selectAccountIdByAddress( $_[12] );
$self->sth_insertTransactionWithContractAddress->execute( @_ ); $self->sth_insertTransactionWithContractAddress->execute( @_, 'explicit' );
} }
__PACKAGE__->mk_accessors( 'sth_insertTransaction' ); __PACKAGE__->mk_accessors( 'sth_insertTransaction' );
...@@ -85,15 +85,16 @@ sub insertTransaction ...@@ -85,15 +85,16 @@ sub insertTransaction
INSERT INTO transaction INSERT INTO transaction
( hash, "blockId", nonce, gas, ( hash, "blockId", nonce, gas,
"gasPrice", value, "fromAccountId","toAccountId", "gasPrice", value, "fromAccountId","toAccountId",
status, "gasUsed", input, inputlen ) status, "gasUsed", input, inputlen,
VALUES (?,?,?,?,?,?,?,?,?,?,?,?) "type" )
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)
)) ))
); );
} }
$_[1] = $self->selectBlockhashByHash( $_[1] ); $_[1] = $self->selectBlockhashByHash( $_[1] );
$_[6] = $self->selectAccountIdByAddress( $_[6] ); $_[6] = $self->selectAccountIdByAddress( $_[6] );
$_[7] = $self->selectAccountIdByAddress( $_[7] ); $_[7] = $self->selectAccountIdByAddress( $_[7] );
$self->sth_insertTransaction->execute( @_ ); $self->sth_insertTransaction->execute( @_, 'explicit' );
} }
__PACKAGE__->mk_accessors( 'sth_selectBlockhashById' ); __PACKAGE__->mk_accessors( 'sth_selectBlockhashById' );
......
...@@ -2,69 +2,186 @@ ...@@ -2,69 +2,186 @@
\connect "postgres"; \connect "postgres";
CREATE SEQUENCE account_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1000 CACHE 1; CREATE TYPE transactiontype
AS ENUM ( 'unknown', 'internal', 'explicit' );
CREATE SEQUENCE account_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 2147483647
START 1000
CACHE 1;
CREATE TABLE "public"."account" ( CREATE TABLE "public"."account" (
"id" bigint DEFAULT nextval('account_id_seq') NOT NULL, "id" bigint
"address" character(42) NOT NULL, DEFAULT nextval('account_id_seq')
"shortname" character varying(16), NOT NULL,
"name" character varying(255), "address" character(42)
CONSTRAINT "account_id" PRIMARY KEY ("id"), NOT NULL,
CONSTRAINT "account_hash" UNIQUE ("address") "shortname" character varying(16),
"name" character varying(255),
CONSTRAINT "account_id"
PRIMARY KEY ("id"),
CONSTRAINT "account_hash"
UNIQUE ("address")
) WITH (oids = false); ) WITH (oids = false);
CREATE SEQUENCE blockhash_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1000000 CACHE 1; CREATE SEQUENCE blockhash_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 2147483647
START 1000000
CACHE 1;
CREATE TABLE "public"."blockhash" ( CREATE TABLE "public"."blockhash" (
"id" bigint DEFAULT nextval('blockhash_id_seq') NOT NULL, "id" bigint
"hash" character(66) NOT NULL, DEFAULT nextval('blockhash_id_seq')
CONSTRAINT "blockhash_id" PRIMARY KEY ("id"), NOT NULL,
CONSTRAINT "blockhash_hash" UNIQUE ("hash") "hash" character(66)
NOT NULL,
CONSTRAINT "blockhash_id"
PRIMARY KEY ("id"),
CONSTRAINT "blockhash_hash"
UNIQUE ("hash")
) WITH (oids = false); ) WITH (oids = false);
CREATE TABLE "public"."block" ( CREATE TABLE "public"."block" (
"id" bigint NOT NULL, "id" bigint NOT NULL,
"parentBlockhashId" bigint, "parentBlockhashId" bigint,
"number" bigint NOT NULL, "number" bigint NOT NULL,
"sealerAccountId" bigint, "sealerAccountId" bigint,
"timestamp" bigint NOT NULL, "timestamp" bigint NOT NULL,
"difficulty" smallint NOT NULL, "difficulty" smallint NOT NULL,
"gasUsed" bigint NOT NULL, "gasUsed" bigint NOT NULL,
"gasLimit" bigint NOT NULL, "gasLimit" bigint NOT NULL,
"size" bigint NOT NULL, "size" bigint NOT NULL,
CONSTRAINT "block_id" PRIMARY KEY ("id"), CONSTRAINT "block_id"
CONSTRAINT "block_sealerAccountId_fkey" FOREIGN KEY ("sealerAccountId") REFERENCES account(id) NOT DEFERRABLE, PRIMARY KEY ("id"),
CONSTRAINT "block_id_fkey" FOREIGN KEY (id) REFERENCES blockhash(id) NOT DEFERRABLE, CONSTRAINT "block_sealerAccountId_fkey"
CONSTRAINT "block_parentBlockhashId_fkey" FOREIGN KEY ("parentBlockhashId") REFERENCES blockhash(id) NOT DEFERRABLE FOREIGN KEY ("sealerAccountId")
REFERENCES account(id)
NOT DEFERRABLE,
CONSTRAINT "block_id_fkey"
FOREIGN KEY (id)
REFERENCES blockhash(id)
NOT DEFERRABLE,
CONSTRAINT "block_parentBlockhashId_fkey"
FOREIGN KEY ("parentBlockhashId")
REFERENCES blockhash(id)
NOT DEFERRABLE
) WITH (oids = false); ) WITH (oids = false);
CREATE INDEX "block_parentBlockHashId" ON "public"."block" USING btree ("parentBlockhashId"); CREATE INDEX "block_parentBlockHashId"
CREATE INDEX "block_sealerAccountId" ON "public"."block" USING btree ("sealerAccountId"); ON "public"."block"
CREATE INDEX "block_number" ON "public"."block" USING btree ("number"); USING btree ("parentBlockhashId");
CREATE INDEX "block_timestamp" ON "public"."block" USING btree ("timestamp"); CREATE INDEX "block_sealerAccountId"
ON "public"."block"
USING btree ("sealerAccountId");
CREATE INDEX "block_number"
ON "public"."block"
USING btree ("number");
CREATE INDEX "block_timestamp"
ON "public"."block"
USING btree ("timestamp");
CREATE TABLE "public"."transaction" ( CREATE TABLE "public"."transaction" (
"hash" character(66) NOT NULL, "hash" character(66)
"blockId" bigint, NOT NULL,
"nonce" bigint NOT NULL, "blockId" bigint,
"gas" bigint NOT NULL, "type" transactiontype
"gasPrice" bigint NOT NULL, DEFAULT 'unknown'
"value" bigint NOT NULL, NOT NULL,
"fromAccountId" bigint NOT NULL, "nonce" bigint
"toAccountId" bigint NOT NULL, NOT NULL,
"contractaddressAccountId" bigint, "gas" bigint
"status" smallint NOT NULL, NOT NULL,
"gasUsed" bigint NOT NULL, "gasPrice" bigint
"inputlen" smallint NOT NULL, NOT NULL,
"input" text NOT NULL, "value" bigint
CONSTRAINT "transaction_contractaddressAccountId_fkey" FOREIGN KEY ("contractaddressAccountId") REFERENCES account(id) NOT DEFERRABLE, NOT NULL,
CONSTRAINT "transaction_fromAccountId_fkey" FOREIGN KEY ("fromAccountId") REFERENCES account(id) NOT DEFERRABLE, "fromAccountId" bigint
CONSTRAINT "transaction_toAccountId_fkey" FOREIGN KEY ("toAccountId") REFERENCES account(id) NOT DEFERRABLE, NOT NULL,
CONSTRAINT "transaction_blockId_fkey" FOREIGN KEY ("blockId") REFERENCES block(id) NOT DEFERRABLE "toAccountId" bigint
NOT NULL,
"contractaddressAccountId"
bigint,
"status" smallint
NOT NULL,
"gasUsed" bigint
NOT NULL,
"inputlen" smallint
NOT NULL,
"input" text
NOT NULL,
CONSTRAINT "transaction_contractaddressAccountId_fkey"
FOREIGN KEY ("contractaddressAccountId")
REFERENCES account(id)
NOT DEFERRABLE,
CONSTRAINT "transaction_fromAccountId_fkey"
FOREIGN KEY ("fromAccountId")
REFERENCES account(id)
NOT DEFERRABLE,
CONSTRAINT "transaction_toAccountId_fkey"
FOREIGN KEY ("toAccountId")
REFERENCES account(id)
NOT DEFERRABLE,
CONSTRAINT "transaction_blockId_fkey"
FOREIGN KEY ("blockId")
REFERENCES block(id)
NOT DEFERRABLE
) WITH (oids = false); ) WITH (oids = false);
CREATE INDEX "transaction_contractaddressAccountId" ON "public"."transaction" USING btree ("contractaddressAccountId"); CREATE INDEX "transaction_contractaddressAccountId"
CREATE INDEX "transaction_fromAccountId" ON "public"."transaction" USING btree ("fromAccountId"); ON "public"."transaction"
CREATE INDEX "transaction_toAccountId" ON "public"."transaction" USING btree ("toAccountId"); USING btree ("contractaddressAccountId");
CREATE INDEX "transaction_blockId" ON "public"."transaction" USING btree ("blockId"); CREATE INDEX "transaction_fromAccountId"
ON "public"."transaction"
USING btree ("fromAccountId");
CREATE INDEX "transaction_toAccountId"
ON "public"."transaction"
USING btree ("toAccountId");
CREATE INDEX "transaction_blockId"
ON "public"."transaction"
USING btree ("blockId");
CREATE VIEW b AS SELECT b1.hash "hash", b2.hash "parentHash", number, account.address sealer, timestamp, difficulty, "gasUsed", "gasLimit", size FROM block, blockhash b1, blockhash b2, account WHERE block.id=b1.id AND block."parentBlockhashId"=b2.id AND block."sealerAccountId"=account.id; CREATE VIEW b
AS
SELECT b1.hash "hash",
b2.hash "parentHash",
number,
account.address sealer,
timestamp,
difficulty,
"gasUsed",
"gasLimit",
size
FROM block,
blockhash b1,
blockhash b2,
account
WHERE block.id = b1.id
AND block."parentBlockhashId"= b2.id
AND block."sealerAccountId" = account.id;
CREATE VIEW t
AS
SELECT transaction.hash "transaction hash",
block.number "block number",
"type",
nonce,
gas,
"gasPrice" "gas price",
value,
a1.address "from",
a2.address "to",
a3.address "contractaddress",
status,
transaction."gasUsed" "gas used",
inputlen
FROM transaction
LEFT JOIN account a3
ON (transaction."contractaddressAccountId" = a3.id),
block,
account a1,
account a2
WHERE block.id = transaction."blockId"
AND a1.id = "fromAccountId"
AND a2.id = "toAccountId";
INSERT INTO "account" ("id", "address", "shortname", "name") VALUES INSERT INTO "account" ("id", "address", "shortname", "name") VALUES
(1, '0x377ab0cd00744dbb07b369cd5c0872dcd362c8f0', 'UNER', 'Universidad Nacional de Entre Rios'), (1, '0x377ab0cd00744dbb07b369cd5c0872dcd362c8f0', 'UNER', 'Universidad Nacional de Entre Rios'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment