From 8e0680e5a73786cb12fddc5c09a77e3fbdd067c0 Mon Sep 17 00:00:00 2001 From: Dmitry Detukov Date: Mon, 8 May 2023 10:55:25 +0300 Subject: [PATCH 01/10] Create database --- .vscode/launch.json | 6 + bin/server.dart | 353 ++++++++++++++++++++++++++++++++++++++- database/address.sql | 4 + database/block.sql | 6 + database/blockchain.sql | 4 + database/explorer.sql | 4 + database/transaction.sql | 5 + pubspec.yaml | 1 + 8 files changed, 379 insertions(+), 4 deletions(-) create mode 100644 database/address.sql create mode 100644 database/block.sql create mode 100644 database/blockchain.sql create mode 100644 database/explorer.sql create mode 100644 database/transaction.sql diff --git a/.vscode/launch.json b/.vscode/launch.json index b9cd1a3..e13db9b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,6 +10,12 @@ "type": "dart", "program": "bin/server.dart", "cwd": "${workspaceFolder}" + },{ + "name": "Test", + "request": "launch", + "type": "dart", + "cwd": "${workspaceFolder}", + "program": "bin/address.dart" } ] } \ No newline at end of file diff --git a/bin/server.dart b/bin/server.dart index 57bd1d6..f28e885 100644 --- a/bin/server.dart +++ b/bin/server.dart @@ -2,9 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// ignore_for_file: prefer_expression_function_bodies + import 'dart:convert'; import 'dart:io'; +import 'package:mustache_template/mustache.dart'; import 'package:shelf/shelf.dart'; import 'package:shelf/shelf_io.dart' as shelf_io; import 'package:shelf_router/shelf_router.dart' as shelf_router; @@ -39,12 +42,17 @@ Future main() async { } // Serve files from the file system. -final _staticHandler = - shelf_static.createStaticHandler('../frontend', defaultDocument: 'index.html'); +final _staticHandler = shelf_static.createStaticHandler( + '../frontend', + defaultDocument: 'index.html', +); // Router instance to handler requests. final _router = shelf_router.Router() - ..get('/helloworld', _helloWorldHandler) + ..get('/search', _search) + ..get('/address/
', _address) + ..get('/transaction/', _transaction) + ..get('/error/', _error) ..get( '/time', (request) => Response.ok(DateTime.now().toUtc().toIso8601String()), @@ -52,7 +60,344 @@ final _router = shelf_router.Router() ..get('/info.json', _infoHandler) ..get('/sum//', _sumHandler); -Response _helloWorldHandler(Request request) => Response.ok('Hello, World!'); +Future _search(Request request) async { + final asset = request.url.queryParameters["q"]; + if (asset == "0xF0245F6251Bef9447A08766b9DA2B07b28aD80B0") { + // await Future.delayed(const Duration(seconds: 3)); + // return Response.movedPermanently("/address"); + return Response(308, headers: {"location": "/address/$asset"}); + } else if (asset == + "0x25eb25e730b5c0f805ec3695040b6c8a2e1ec68effc884c3ec5b7e6dd038d1a8") { + return Response(308, headers: {"location": "/transaction/$asset"}); + } else { + return Response(308, headers: {"location": "/error/$asset"}); + } +} + +Future _address(Request request, String address) async { + final String source = await File('../frontend/address-1.html').readAsString(); + + var template = Template(source, name: 'address'); + + var output = template.renderString({ + "address": address, + "assets": [ + { + "id": "BNB", + "balance": [ + { + "amount": 0.10038, + "value": 5, + } + ], + "blockchains": [ + { + "blockchain": "Binance Smart Coin", + "token": false, + "balance": [ + { + "amount": 0.00038, + "value": 1, + } + ], + "alternatives": [ + { + "name": "com.bscscan", + "favicon": "https://bscscan.com/images/favicon.ico", + "link": + "https://bscscan.com/address/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + { + "name": "io.binance.mintscan", + "favicon": "https://binance.mintscan.io/favicon.ico", + "link": + "https://binance.mintscan.io/account/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + ], + }, + { + "blockchain": "Ethereum", + "token": true, + "balance": [ + { + "amount": 0.1, + "value": 4, + } + ], + "alternatives": [ + { + "name": "io.etherscan", + "favicon": "https://etherscan.io/images/favicon3.ico", + "link": + "https://etherscan.io/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + { + "name": "io.explorer.bitquery", + "favicon": + "https://bitquery.io/wp-content/uploads/2020/09/favicon.png", + "link": + "https://explorer.bitquery.io/bsc/address/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + ] + } + ], + "name": "Binance Coin" + }, + { + "id": "BUSD-T", + "balance": [ + { + "amount": 0.219, + "value": 2, + } + ], + "blockchains": [ + { + "blockchain": "Ethereum", + "token": true, + "balance": [ + { + "amount": 0.219, + "value": 2, + } + ], + "alternatives": [ + { + "name": "com.bscscan", + "favicon": "https://bscscan.com/images/favicon.ico", + "link": + "https://bscscan.com/token/0x55d398326f99059ff775485246999027b3197955?a=0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + { + "name": "io.explorer.bitquery", + "favicon": + "https://bitquery.io/wp-content/uploads/2020/09/favicon.png", + "link": + "https://explorer.bitquery.io/bsc/token/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + ], + } + ], + "name": "BUSD Token" + }, + { + "id": "ETH", + "balance": [ + { + "amount": 5.06587, + "value": 15, + } + ], + "blockchains": [ + { + "blockchain": "Ethereum", + "token": false, + "balance": [ + { + "amount": 4.06587, + "value": 10, + } + ], + "alternatives": [ + { + "name": "io.etherscan", + "favicon": "https://etherscan.io/images/favicon3.ico", + "link": + "https://etherscan.io/address/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + { + "name": "io.ethplorer", + "favicon": "https://ethplorer.io/icons-29d214c3/favicon.ico", + "link": + "https://ethplorer.io/address/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + { + "name": "org.etherchain", + "favicon": "https://beaconcha.in/favicon.ico", + "link": + "https://etherchain.org/account/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + ], + }, + { + "blockchain": "Binance Smart Coin", + "token": true, + "balance": [ + { + "amount": 1.06587, + "value": 5, + } + ], + "alternatives": [ + { + "name": "com.bscscan", + "favicon": "https://bscscan.com/images/favicon.ico", + "link": + "https://bscscan.com/token/0x2170ed0880ac9a755fd29b2688956bd959f933f8?a=0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + ] + } + ], + "name": "Ether" + }, + { + "id": "MATIC", + "balance": [ + { + "amount": 56.124, + "value": 25, + } + ], + "blockchains": [ + { + "blockchain": "Ethereum", + "token": true, + "balance": [ + { + "amount": 50.124, + "value": 15, + } + ], + "alternatives": [ + { + "name": "com.blockchain", + "favicon": + "https://loutre.blockchair.io/assets/favicons/icon.svg", + "link": + "https://blockchair.com/ethereum/erc-20/token/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + { + "name": "io.explorer.bitquery", + "favicon": + "https://bitquery.io/wp-content/uploads/2020/09/favicon.png", + "link": + "https://explorer.bitquery.io/matic/address/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + ], + }, + { + "blockchain": "Polygon", + "token": false, + "balance": [ + { + "amount": 6, + "value": 10, + } + ], + "alternatives": [ + { + "name": "com.polygonscan", + "favicon": "https://polygonscan.com/images/favicon.ico", + "link": + "https://polygonscan.com/address/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + ] + } + ], + "name": "Polygon" + }, + { + "id": "USDT", + "balance": [ + { + "amount": 39, + "value": 25, + } + ], + "blockchains": [ + { + "blockchain": "Ethereum", + "token": true, + "balance": [ + { + "amount": 30, + "value": 15, + } + ], + "alternatives": [ + { + "name": "io.etherscan", + "favicon": "https://etherscan.io/images/favicon3.ico", + "link": + "https://etherscan.io/token/0xdac17f958d2ee523a2206206994597c13d831ec7?a=0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + { + "name": "io.ethplorer", + "favicon": "https://ethplorer.io/icons-29d214c3/favicon.ico", + "link": + "https://ethplorer.io/address/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + { + "name": "org.etherchain", + "favicon": "https://beaconcha.in/favicon.ico", + "link": + "https://etherchain.org/account/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + ], + }, + { + "blockchain": "Tron", + "token": true, + "balance": [ + { + "amount": 9, + "value": 10, + } + ], + "alternatives": [ + { + "name": "org.tronscan", + "favicon": "https://tronscan.org/favicon.png?v=2", + "link": + "https://tronscan.org/#/address/0x2b6828f4f227953fb36f42bda830b457afdc1c5e/" + }, + ] + } + ], + "name": "Tether" + } + ] + }); + + return Response.ok(output, headers: {"content-type": "text/html"}); +} + +Future _transaction(Request request, String transaction) async { + final String source = + await File('../frontend/transaction.html').readAsString(); + + var template = Template(source, name: 'transaction'); + + var output = template.renderString({ + "transaction": transaction, + "explorers": [ + { + "name": "io.etherscan", + "favicon": "https://etherscan.io/images/favicon3.ico", + "link": + "https://etherscan.io/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + { + "name": "io.ethplorer", + "favicon": "https://ethplorer.io/icons-29d214c3/favicon.ico", + "link": + "https://ethplorer.io/address/0x2b6828f4f227953fb36f42bda830b457afdc1c5e" + }, + ] + }); + + return Response.ok(output, headers: {"content-type": "text/html"}); +} + +Future _error(Request request, String error) async { + final String source = await File('../frontend/error.html').readAsString(); + + var template = Template(source, name: 'error'); + + var output = template.renderString({"error": error}); + + return Response.ok(output, headers: {"content-type": "text/html"}); +} String _jsonEncode(Object? data) => const JsonEncoder.withIndent(' ').convert(data); diff --git a/database/address.sql b/database/address.sql new file mode 100644 index 0000000..db253b2 --- /dev/null +++ b/database/address.sql @@ -0,0 +1,4 @@ +CREATE TABLE address ( + id BIGINT PRIMARY KEY, + balance NUMERIC(48,24) +); diff --git a/database/block.sql b/database/block.sql new file mode 100644 index 0000000..caf509b --- /dev/null +++ b/database/block.sql @@ -0,0 +1,6 @@ +CREATE TABLE block ( + id BIGINT PRIMARY KEY, + number_id BIGINT, + hash BYTEA, + parent_hash BYTEA +); \ No newline at end of file diff --git a/database/blockchain.sql b/database/blockchain.sql new file mode 100644 index 0000000..6a300ae --- /dev/null +++ b/database/blockchain.sql @@ -0,0 +1,4 @@ +CREATE TABLE blockchain ( + id BIGINT PRIMARY KEY, + blockchain CHARACTER VARYING(100) +); \ No newline at end of file diff --git a/database/explorer.sql b/database/explorer.sql new file mode 100644 index 0000000..d5b802f --- /dev/null +++ b/database/explorer.sql @@ -0,0 +1,4 @@ +CREATE TABLE explorer ( + id BIGINT PRIMARY KEY, + explorer CHARACTER VARYING(100) +); \ No newline at end of file diff --git a/database/transaction.sql b/database/transaction.sql new file mode 100644 index 0000000..6ea4436 --- /dev/null +++ b/database/transaction.sql @@ -0,0 +1,5 @@ +CREATE TABLE transaction ( + id BIGINT PRIMARY KEY, + hash BYTEA, + amount NUMERIC(48,24) +); \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 88e19f4..548419b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,6 +5,7 @@ environment: sdk: ">=2.12.0 <3.0.0" dependencies: + mustache_template: ^2.0.0 shelf: ^1.2.0 shelf_router: ^1.0.0 shelf_static: ^1.0.0 From 4a36ecd93ba83c6d31da4803063e292dab42899e Mon Sep 17 00:00:00 2001 From: Dmitry Detukov Date: Mon, 8 May 2023 12:54:13 +0300 Subject: [PATCH 02/10] Fixed data block and explorer --- database/blockchain.sql | 2 +- database/explorer.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/database/blockchain.sql b/database/blockchain.sql index 6a300ae..69d819d 100644 --- a/database/blockchain.sql +++ b/database/blockchain.sql @@ -1,4 +1,4 @@ CREATE TABLE blockchain ( id BIGINT PRIMARY KEY, - blockchain CHARACTER VARYING(100) + blockchain_id CHARACTER VARYING(100) ); \ No newline at end of file diff --git a/database/explorer.sql b/database/explorer.sql index d5b802f..d6da8b6 100644 --- a/database/explorer.sql +++ b/database/explorer.sql @@ -1,4 +1,4 @@ CREATE TABLE explorer ( id BIGINT PRIMARY KEY, - explorer CHARACTER VARYING(100) + explorer_id CHARACTER VARYING(100) ); \ No newline at end of file From 721606870d2d6e79bc842dbe9ca946d6381827d4 Mon Sep 17 00:00:00 2001 From: Dmitry Detukov Date: Tue, 9 May 2023 11:35:24 +0300 Subject: [PATCH 03/10] Fixed create tables --- database/address.sql | 7 ++++--- database/block.sql | 12 +++++++----- database/blockchain.sql | 6 +++--- database/explorer.sql | 6 +++--- database/transaction.sql | 8 ++++---- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/database/address.sql b/database/address.sql index db253b2..25af100 100644 --- a/database/address.sql +++ b/database/address.sql @@ -1,4 +1,5 @@ -CREATE TABLE address ( - id BIGINT PRIMARY KEY, - balance NUMERIC(48,24) +CREATE TABLE "address" ( + "id" BIGINT PRIMARY KEY NOT NULL, + "address" BYTEA, + "balance" NUMERIC(48,24) ); diff --git a/database/block.sql b/database/block.sql index caf509b..f827c49 100644 --- a/database/block.sql +++ b/database/block.sql @@ -1,6 +1,8 @@ -CREATE TABLE block ( - id BIGINT PRIMARY KEY, - number_id BIGINT, - hash BYTEA, - parent_hash BYTEA +CREATE TABLE "block" ( + "id" BIGINT PRIMARY KEY NOT NULL, + "number" BIGINT NOT NULL, + "hash" BYTEA NOT NULL, + "parent_hash" BYTEA NOT NULL, + "blockchain_id" BIGINT NOT NULL, + CONSTRAINT "fk__block__blockchain" FOREIGN KEY ("blockchain_id") REFERENCES "blockchain" ("id") ); \ No newline at end of file diff --git a/database/blockchain.sql b/database/blockchain.sql index 69d819d..b9626f2 100644 --- a/database/blockchain.sql +++ b/database/blockchain.sql @@ -1,4 +1,4 @@ -CREATE TABLE blockchain ( - id BIGINT PRIMARY KEY, - blockchain_id CHARACTER VARYING(100) +CREATE TABLE "blockchain" ( + "id" BIGINT PRIMARY KEY NOT NULL, + "name" CHARACTER VARYING(100) ); \ No newline at end of file diff --git a/database/explorer.sql b/database/explorer.sql index d6da8b6..a991b2c 100644 --- a/database/explorer.sql +++ b/database/explorer.sql @@ -1,4 +1,4 @@ -CREATE TABLE explorer ( - id BIGINT PRIMARY KEY, - explorer_id CHARACTER VARYING(100) +CREATE TABLE "explorer" ( + "id" BIGINT PRIMARY KEY NOT NULL, + "explorer" CHARACTER VARYING(100) ); \ No newline at end of file diff --git a/database/transaction.sql b/database/transaction.sql index 6ea4436..7b3fe4a 100644 --- a/database/transaction.sql +++ b/database/transaction.sql @@ -1,5 +1,5 @@ -CREATE TABLE transaction ( - id BIGINT PRIMARY KEY, - hash BYTEA, - amount NUMERIC(48,24) +CREATE TABLE "transaction" ( + "id" BIGINT PRIMARY KEY NOT NULL, + "hash" BYTEA NOT NULL, + "amount" NUMERIC(48,24) ); \ No newline at end of file From 4f926f4ac0ec4b4c694689a085eaef15d77c0d32 Mon Sep 17 00:00:00 2001 From: Dmitry Detukov Date: Tue, 9 May 2023 14:42:29 +0300 Subject: [PATCH 04/10] Fixed structure of database --- database/address.sql | 4 ++-- database/block.sql | 8 ++++++-- database/blockchain.sql | 10 +++++++--- database/explorer.sql | 4 ++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/database/address.sql b/database/address.sql index 25af100..94feb83 100644 --- a/database/address.sql +++ b/database/address.sql @@ -1,5 +1,5 @@ CREATE TABLE "address" ( - "id" BIGINT PRIMARY KEY NOT NULL, - "address" BYTEA, + "id" BIGINT PRIMARY KEY NOT NULL, + "address" BYTEA NOT NULL, "balance" NUMERIC(48,24) ); diff --git a/database/block.sql b/database/block.sql index f827c49..695d682 100644 --- a/database/block.sql +++ b/database/block.sql @@ -1,8 +1,12 @@ +CREATE SEQUENCE "block_id_seq" START 1; + CREATE TABLE "block" ( - "id" BIGINT PRIMARY KEY NOT NULL, + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('blockchain_id_seq'), "number" BIGINT NOT NULL, "hash" BYTEA NOT NULL, "parent_hash" BYTEA NOT NULL, "blockchain_id" BIGINT NOT NULL, CONSTRAINT "fk__block__blockchain" FOREIGN KEY ("blockchain_id") REFERENCES "blockchain" ("id") -); \ No newline at end of file +); + +-- ALTER TABLE "block" ALTER COLUMN "id" SET DEFAULT NEXTVAL('block_id_seq'); \ No newline at end of file diff --git a/database/blockchain.sql b/database/blockchain.sql index b9626f2..c8b5494 100644 --- a/database/blockchain.sql +++ b/database/blockchain.sql @@ -1,4 +1,8 @@ +CREATE SEQUENCE "blockchain_id_seq" START 1; + CREATE TABLE "blockchain" ( - "id" BIGINT PRIMARY KEY NOT NULL, - "name" CHARACTER VARYING(100) -); \ No newline at end of file + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('blockchain_id_seq'), + "name" CHARACTER VARYING(100) NOT NULL +); + +-- ALTER TABLE "blockchain" ALTER COLUMN "id" SET DEFAULT NEXTVAL('blockchain_id_seq'); diff --git a/database/explorer.sql b/database/explorer.sql index a991b2c..15e4866 100644 --- a/database/explorer.sql +++ b/database/explorer.sql @@ -1,4 +1,4 @@ CREATE TABLE "explorer" ( - "id" BIGINT PRIMARY KEY NOT NULL, - "explorer" CHARACTER VARYING(100) + "id" BIGINT PRIMARY KEY NOT NULL, + "explorer" CHARACTER VARYING(100) NOT NULL ); \ No newline at end of file From e625d5ed2c48583e2707f1dd75cb80266a482dac Mon Sep 17 00:00:00 2001 From: Dmitry Detukov Date: Tue, 9 May 2023 17:06:42 +0300 Subject: [PATCH 05/10] Fixed create sequence --- database/address.sql | 4 +++- database/block.sql | 8 ++++++-- database/blockchain.sql | 1 - database/explorer.sql | 4 +++- database/transaction.sql | 7 +++++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/database/address.sql b/database/address.sql index 94feb83..7b77cf7 100644 --- a/database/address.sql +++ b/database/address.sql @@ -1,5 +1,7 @@ +CREATE SEQUENCE "address_id_seq" START 1; + CREATE TABLE "address" ( - "id" BIGINT PRIMARY KEY NOT NULL, + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('address_id_seq'), "address" BYTEA NOT NULL, "balance" NUMERIC(48,24) ); diff --git a/database/block.sql b/database/block.sql index 695d682..7a050c0 100644 --- a/database/block.sql +++ b/database/block.sql @@ -1,7 +1,7 @@ CREATE SEQUENCE "block_id_seq" START 1; CREATE TABLE "block" ( - "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('blockchain_id_seq'), + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('blockchain_id_seq'), "number" BIGINT NOT NULL, "hash" BYTEA NOT NULL, "parent_hash" BYTEA NOT NULL, @@ -9,4 +9,8 @@ CREATE TABLE "block" ( CONSTRAINT "fk__block__blockchain" FOREIGN KEY ("blockchain_id") REFERENCES "blockchain" ("id") ); --- ALTER TABLE "block" ALTER COLUMN "id" SET DEFAULT NEXTVAL('block_id_seq'); \ No newline at end of file +-- ALTER TABLE "block" ALTER COLUMN "id" SET DEFAULT NEXTVAL('block_id_seq'); + +-- INSERT INTO public.block( +-- "number", hash, parent_hash, blockchain_id) +-- VALUES (567789, ('\x00000000030a4e13565e8e89e26f838c62816460fb2b3f76b8f654aa802e37ce'::bytea), ('\x00000000030a4e12ad81558fbc78f10e1c38c7c64114e83150438c029c820424'::bytea), 1); \ No newline at end of file diff --git a/database/blockchain.sql b/database/blockchain.sql index c8b5494..70a5e0f 100644 --- a/database/blockchain.sql +++ b/database/blockchain.sql @@ -5,4 +5,3 @@ CREATE TABLE "blockchain" ( "name" CHARACTER VARYING(100) NOT NULL ); --- ALTER TABLE "blockchain" ALTER COLUMN "id" SET DEFAULT NEXTVAL('blockchain_id_seq'); diff --git a/database/explorer.sql b/database/explorer.sql index 15e4866..53ca063 100644 --- a/database/explorer.sql +++ b/database/explorer.sql @@ -1,4 +1,6 @@ +CREATE SEQUENCE "explorer_id_seq" START 1; + CREATE TABLE "explorer" ( - "id" BIGINT PRIMARY KEY NOT NULL, + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('explorer_id_seq'), "explorer" CHARACTER VARYING(100) NOT NULL ); \ No newline at end of file diff --git a/database/transaction.sql b/database/transaction.sql index 7b3fe4a..525dbdb 100644 --- a/database/transaction.sql +++ b/database/transaction.sql @@ -1,5 +1,8 @@ +CREATE SEQUENCE "transaction_id_seq" START 1; + CREATE TABLE "transaction" ( - "id" BIGINT PRIMARY KEY NOT NULL, + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('block_id_seq'), "hash" BYTEA NOT NULL, - "amount" NUMERIC(48,24) + "amount" NUMERIC(48,24), + CONSTRAINT "fk__transaction__block" FOREIGN KEY ("block_id") REFERENCES "block" ("id") ); \ No newline at end of file From 4da2f38d205858bcaeb0956d2d06c4f2b2872a29 Mon Sep 17 00:00:00 2001 From: Dmitry Detukov Date: Tue, 9 May 2023 17:18:52 +0300 Subject: [PATCH 06/10] Fixed foreign_key for transaction and block --- database/block.sql | 2 +- database/explorer.sql | 2 +- database/transaction.sql | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/database/block.sql b/database/block.sql index 7a050c0..7fcde83 100644 --- a/database/block.sql +++ b/database/block.sql @@ -1,7 +1,7 @@ CREATE SEQUENCE "block_id_seq" START 1; CREATE TABLE "block" ( - "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('blockchain_id_seq'), + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('block_id_seq'), "number" BIGINT NOT NULL, "hash" BYTEA NOT NULL, "parent_hash" BYTEA NOT NULL, diff --git a/database/explorer.sql b/database/explorer.sql index 53ca063..a02d427 100644 --- a/database/explorer.sql +++ b/database/explorer.sql @@ -1,6 +1,6 @@ CREATE SEQUENCE "explorer_id_seq" START 1; CREATE TABLE "explorer" ( - "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('explorer_id_seq'), + "id" BIGINT PRIMARY KEY NOT NULL, "explorer" CHARACTER VARYING(100) NOT NULL ); \ No newline at end of file diff --git a/database/transaction.sql b/database/transaction.sql index 525dbdb..1bc19bc 100644 --- a/database/transaction.sql +++ b/database/transaction.sql @@ -1,8 +1,9 @@ CREATE SEQUENCE "transaction_id_seq" START 1; CREATE TABLE "transaction" ( - "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('block_id_seq'), + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('transaction_id_seq'), "hash" BYTEA NOT NULL, "amount" NUMERIC(48,24), + "block_id" BIGINT NOT NULL, CONSTRAINT "fk__transaction__block" FOREIGN KEY ("block_id") REFERENCES "block" ("id") ); \ No newline at end of file From 904d05ae252499aa0454c95860105433c33f4ab9 Mon Sep 17 00:00:00 2001 From: Dmitry Detukov Date: Tue, 9 May 2023 17:36:14 +0300 Subject: [PATCH 07/10] Added constraint to address --- database/address.sql | 8 +++++--- database/transaction.sql | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/database/address.sql b/database/address.sql index 7b77cf7..ae25c89 100644 --- a/database/address.sql +++ b/database/address.sql @@ -1,7 +1,9 @@ CREATE SEQUENCE "address_id_seq" START 1; CREATE TABLE "address" ( - "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('address_id_seq'), - "address" BYTEA NOT NULL, - "balance" NUMERIC(48,24) + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('address_id_seq'), + "address" BYTEA NOT NULL, + "balance" NUMERIC(48,24), + "transaction_id" BIGINT NOT NULL, + CONSTRAINT "fk__address__block" FOREIGN KEY ("transaction_id") REFERENCES "transaction" ("id") ); diff --git a/database/transaction.sql b/database/transaction.sql index 1bc19bc..8177658 100644 --- a/database/transaction.sql +++ b/database/transaction.sql @@ -4,6 +4,6 @@ CREATE TABLE "transaction" ( "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('transaction_id_seq'), "hash" BYTEA NOT NULL, "amount" NUMERIC(48,24), - "block_id" BIGINT NOT NULL, + "block_id" BIGINT NOT NULL, CONSTRAINT "fk__transaction__block" FOREIGN KEY ("block_id") REFERENCES "block" ("id") ); \ No newline at end of file From 92e8c69cac54b033e0eda575c9dcee523d452095 Mon Sep 17 00:00:00 2001 From: Dmitry Detukov Date: Tue, 9 May 2023 17:48:03 +0300 Subject: [PATCH 08/10] Fixed explorer --- database/explorer.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/explorer.sql b/database/explorer.sql index a02d427..6450449 100644 --- a/database/explorer.sql +++ b/database/explorer.sql @@ -1,6 +1,6 @@ CREATE SEQUENCE "explorer_id_seq" START 1; CREATE TABLE "explorer" ( - "id" BIGINT PRIMARY KEY NOT NULL, + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('explorer_id_seq'),, "explorer" CHARACTER VARYING(100) NOT NULL ); \ No newline at end of file From 0d464bcb61ccb40707c4a8c11ce9e12e564c0e53 Mon Sep 17 00:00:00 2001 From: Dmitry Detukov Date: Tue, 9 May 2023 17:50:25 +0300 Subject: [PATCH 09/10] Added foreign_key to blockchain --- database/blockchain.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/database/blockchain.sql b/database/blockchain.sql index 70a5e0f..4a7fdaa 100644 --- a/database/blockchain.sql +++ b/database/blockchain.sql @@ -2,6 +2,8 @@ CREATE SEQUENCE "blockchain_id_seq" START 1; CREATE TABLE "blockchain" ( "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('blockchain_id_seq'), - "name" CHARACTER VARYING(100) NOT NULL + "name" CHARACTER VARYING(100) NOT NULL, + "explorer_id" BIGINT NOT NULL, + CONSTRAINT "fk__explorer__block" FOREIGN KEY ("explorer_id") REFERENCES "explorer" ("id") ); From 19d1ad255f7fc1e2111aad7508a6f4b71f8a9d8c Mon Sep 17 00:00:00 2001 From: Dmitry Detukov Date: Fri, 19 May 2023 11:16:26 +0300 Subject: [PATCH 10/10] Added explorer_spec --- database/address.sql | 9 ++++++ database/block.sql | 11 ++++++- database/blockchain.sql | 14 +++++++-- database/explorer.sql | 31 ++++++++++++++++--- database/explorer_spec.sql | 62 ++++++++++++++++++++++++++++++++++++++ database/transaction.sql | 18 ++++++++--- pubspec.yaml | 1 + 7 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 database/explorer_spec.sql diff --git a/database/address.sql b/database/address.sql index ae25c89..c30446f 100644 --- a/database/address.sql +++ b/database/address.sql @@ -7,3 +7,12 @@ CREATE TABLE "address" ( "transaction_id" BIGINT NOT NULL, CONSTRAINT "fk__address__block" FOREIGN KEY ("transaction_id") REFERENCES "transaction" ("id") ); + + +-- INSERT INTO public.address( +-- address, balance, transaction_id) +-- VALUES (('TYL7z7VSVRShLoJ6YRQMA4t9pSECt9ZLtr'::bytea), 997224171.14, 12), +-- (('TLbkcH7QLcULY8dpPAbD9EYGLUWKbeRxuB'::bytea), 997224171.15, 13), +-- (('TFKSWmnRJkzCfWUr56DQ1zqGCxZLW9dKSv'::bytea), 997224171.16, 14), +-- (('3FZbgi29cpjq2GjdwV8eyHuJJnkLtktZc5'::bytea), 0.01847823, 15), +-- (('3FZbgi29cpjq2GjdwV8eyHuJJnkLtktZd8'::bytea), 0.01847824, 13); \ No newline at end of file diff --git a/database/block.sql b/database/block.sql index 7fcde83..a116ffb 100644 --- a/database/block.sql +++ b/database/block.sql @@ -13,4 +13,13 @@ CREATE TABLE "block" ( -- INSERT INTO public.block( -- "number", hash, parent_hash, blockchain_id) --- VALUES (567789, ('\x00000000030a4e13565e8e89e26f838c62816460fb2b3f76b8f654aa802e37ce'::bytea), ('\x00000000030a4e12ad81558fbc78f10e1c38c7c64114e83150438c029c820424'::bytea), 1); \ No newline at end of file +-- VALUES (567789, ('\x00000000030a4e13565e8e89e26f838c62816460fb2b3f76b8f654aa802e37ce'::bytea), ('\x00000000030a4e12ad81558fbc78f10e1c38c7c64114e83150438c029c820424'::bytea), 1); + +-- INSERT INTO public.block( +-- "number", hash, parent_hash, blockchain_id) +-- VALUES (51090247, ('\x00000000030b934bce29e0d17d630fda98333daeafa24eb250f2ff06b484f244'::bytea), ('\x00000000030b934a61d20c4d88ab8414448a44f205db2d54e4a256c2fd3b4f0a'::bytea), 1), +-- (51090258, ('\x00000000030b93ff8628b8ed45ffe851d847401d91005c5ee46334a0717c2f2f'::bytea), ('\x00000000030b93fe787c1b89044acdb1ce7eb113b5d93cfb1101bc1644fb86c9'::bytea), 1), +-- (51090257, ('\x00000000030b949b63ed86e9409c03d55547298fca788cca5c927f99051834ee'::bytea), ('\x00000000030b949a41d3e50cb990f5af7a03951977faecbafc7803a21133441d'::bytea), 1), +-- (51090195, ('\x00000000030b94a32a799b9e4c7b6d5319a994f78857f51fe4cdab543ca120bb'::bytea), ('\x00000000030b94a20867d271c2e0552f2188298d4b3d849c4546a4e33ae845f5'::bytea), 1), +-- (789384, ('\x00000000000000000001ff4178367363678156ce86d7c4a8a5b35457bb1780df'::bytea), ('\x9a3147a6319f4f8592e9a9b3541dbfd318af34a8a6441d59ac7e549c74e607ad'::bytea), 2), +-- (789373, ('\x00000000000000000000343505c376a3913da102c0bf3df22b42d573e2cb2e64'::bytea), ('\x201e77e86a962bb6b532b9e398a7e1f2047bff1fa87f1f5e6ffd5eb1576feb9f'::bytea), 2); \ No newline at end of file diff --git a/database/blockchain.sql b/database/blockchain.sql index 4a7fdaa..7082c8a 100644 --- a/database/blockchain.sql +++ b/database/blockchain.sql @@ -3,7 +3,17 @@ CREATE SEQUENCE "blockchain_id_seq" START 1; CREATE TABLE "blockchain" ( "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('blockchain_id_seq'), "name" CHARACTER VARYING(100) NOT NULL, - "explorer_id" BIGINT NOT NULL, - CONSTRAINT "fk__explorer__block" FOREIGN KEY ("explorer_id") REFERENCES "explorer" ("id") + -- "explorer_id" BIGINT NOT NULL, + -- CONSTRAINT "fk__explorer__block" FOREIGN KEY ("explorer_id") REFERENCES "explorer" ("id") ); + +-- INSERT INTO public.blockchain( +-- name) +-- VALUES ('Bitcoin'), +-- ('Litecoin'), +-- ('Ethereum'), +-- ('TRON'), +-- ('Solana'), +-- ('Cardano'), +-- ('Polygon'); diff --git a/database/explorer.sql b/database/explorer.sql index 6450449..ec6e6c2 100644 --- a/database/explorer.sql +++ b/database/explorer.sql @@ -1,6 +1,29 @@ CREATE SEQUENCE "explorer_id_seq" START 1; - CREATE TABLE "explorer" ( - "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('explorer_id_seq'),, - "explorer" CHARACTER VARYING(100) NOT NULL -); \ No newline at end of file + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('explorer_id_seq'), + "name" CHARACTER VARYING(100) NOT NULL +); +INSERT INTO public.explorer(name) +VALUES ('Blockchain'), + ('Blockcypher'), + ('BinancemintscanExplorer'), + ('BitqueryExplorer'), + ('BscscanExplorer'), + ('EtherscanExplorer'), + ('BitinfochartsExplorer'), + ('BlockchairExplorer'), + ('BlockexplorerExplorer'), + ('BtcExplorer'), + ('ChainzcryptoidExplorer'), + ('DashblockExplorer'), + ('DogechainExplorer'), + ('EtherchainExplorer'), + ('EtherscanExplorer'), + ('EthplorerExplorer'), + ('LitecoinblockExplorer'), + ('PolygonscanExplorer'), + ('TronscanExplorer'), + + + + \ No newline at end of file diff --git a/database/explorer_spec.sql b/database/explorer_spec.sql new file mode 100644 index 0000000..7b6064f --- /dev/null +++ b/database/explorer_spec.sql @@ -0,0 +1,62 @@ +CREATE SEQUENCE "explorer_spec_id_seq" START 1; + +CREATE TABLE "explorer_spec" ( + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('explorer_spec_id_seq'), + "explorer_id" BIGINT NOT NULL, + "explorer_url" CHARACTER VARYING(200) NOT NULL, + "tx_url" CHARACTER VARYING(300) NOT NULL, + "address_url" CHARACTER VARYING(300) NOT NULL, + "token_url" CHARACTER VARYING(300), + "block_url" CHARACTER VARYING(300) NOT NULL, + "blockchain_id" BIGINT NOT NULL, + CONSTRAINT "fk__explorer_spec__blockchain" FOREIGN KEY ("blockchain_id") REFERENCES "blockchain" ("id") +); + +INSERT INTO public.explorer( + explorer_id, explorer_url, tx_url, address_url, token_url, block_url, blockchain_id) + VALUES +(1, 'https://www.blockchain.com/en/', 'https://www.blockchain.com/explorer/transactions/btc/{0}', 'https://www.blockchain.com/explorer/addresses/btc/{0}', 'https://www.blockchain.com/explorer/blocks/btc/{0}', 1), +(1, 'https://www.blockchain.com/en/', 'https://www.blockchain.com/explorer/transactions/eth/{0}', 'https://www.blockchain.com/explorer/addresses/eth/{0}', 'https://www.blockchain.com/explorer/blocks/eth/{0}', 1), +(1, 'https://www.blockchain.com/en/', 'https://www.blockchain.com/explorer/transactions/bch/{0}', 'https://www.blockchain.com/explorer/addresses/bch/{0}', 'https://www.blockchain.com/explorer/blocks/bch/{0}', 1), + + +(2, 'https://www.blockcypher.com/', 'https://live.blockcypher.com/ltc/tx/{0}', 'https://live.blockcypher.com/ltc/address/{0}', 'https://live.blockcypher.com/ltc/block/{0}', 2), +(2, 'https://www.blockcypher.com/', 'https://live.blockcypher.com/doge/tx/{0}', 'https://live.blockcypher.com/doge/address/{0}', 'https://live.blockcypher.com/doge/block/{0}', 2), +(2, 'https://www.blockcypher.com/', 'https://live.blockcypher.com/dash/tx/{0}', 'https://live.blockcypher.com/dash/address/{0}', 'https://live.blockcypher.com/dash/block/{0}', 2), + + +(3, 'https://binance.mintscan.io/', 'https://binance.mintscan.io/txs/{0}', 'https://binance.mintscan.io/account/{0}', 'https://www.mintscan.io/blocks/{0}', 3), +(3, 'https://binance.mintscan.io/', 'https://binance.mintscan.io/cosmos/txs/{0}', 'https://binance.mintscan.io/cosmos/account/{0}', 'https://www.mintscan.io/cosmos/blocks/{0}', 3), +(3, 'https://binance.mintscan.io/', 'https://binance.mintscan.io/quasar/txs/{0}', 'https://binance.mintscan.io/quasar/account/{0}', 'https://www.mintscan.io/quasar/blocks/{0}', 3), + +(4, 'https://bscscan.com/', 'https://bscscan.com/tx/{0}', 'https://bscscan.com/address/{0}', 'https://bscscan.com/token/{1}?a={0}', 'https://bscscan.com/block/{0}', 4), + +(5, 'https://etherscan.io/', 'https://etherscan.io/tx/{0}', 'https://etherscan.io/address/{0}', 'https://etherscan.io/token/{1}?a={0}', 'https://etherscan.io/block/{0}', 6), + +(6, 'https://bitinfocharts.com/', 'https://bitinfocharts.com/bitcoin/tx/{0}', 'https://bitinfocharts.com/bitcoin/address/{0}', 'https://bitinfocharts.com/en/bitcoin/block/{0}', 4), +(6, 'https://bitinfocharts.com/', 'https://bitinfocharts.com/litecoin/tx/{0}', 'https://bitinfocharts.com/litecoin/address/{0}', 'https://bitinfocharts.com/litecoin/block/{0}', 4), +(6, 'https://bitinfocharts.com/', 'https://bitinfocharts.com/dogecoin/tx/{0}', 'https://bitinfocharts.com/dogecoin/address/{0}', 'https://bitinfocharts.com/dogecoin/block/{0}', 4), + +(7, 'https://blockchair.com/', 'https://blockchair.com/bitcoin/transaction/{0}', 'https://blockchair.com/bitcoin/address/{0}', 'https://blockchair.com/bitcoin/block/{0}', 5), +(7, 'https://blockchair.com/', 'https://blockchair.com/ethereum/transaction/{0}', 'https://blockchair.com/ethereum/address/{0}', 'https://blockchair.com/ethereum/block/{0}', 5), + +(8, 'https://blockexplorer.one/', 'https://blockexplorer.one/bitcoin/mainnet/tx/{0}', 'https://blockexplorer.one/bitcoin/mainnet/address/{0}', 'https://blockexplorer.one/bitcoin/mainnet/blockHash/{0}', 7), +(8, 'https://blockexplorer.one/', 'https://blockexplorer.one/litecoin/mainnet/tx/{0}', 'https://blockexplorer.one/litecoin/mainnet/address/{0}', 'https://blockexplorer.one/litecoin/mainnet/blockHash/{0}', 7), +(8, 'https://blockexplorer.one/', 'https://blockexplorer.one/ethereum/mainnet/tx/{0}', 'https://blockexplorer.one/ethereum/mainnet/address/{0}', 'https://blockexplorer.one/ethereum/mainnet/blockHash/{0}', 7), + +(9, 'https://chainz.cryptoid.info/', 'https://btc.cryptoid.info/btc/tx.dws?{0}.htm', 'https://btc.cryptoid.info/btc/address.dws?{0}.htm', 'https://btc.cryptoid.info/btc/block.dws?{0}.htm', 9), +(9, 'https://chainz.cryptoid.info/', 'https://btc.cryptoid.info/ltc/tx.dws?{0}.htm', 'https://btc.cryptoid.info/ltc/address.dws?{0}.htm', 'https://chainz.cryptoid.info/ltc/block.dws?{0}.htm', 9), +(9, 'https://chainz.cryptoid.info/', 'https://btc.cryptoid.info/ion/tx.dws?{0}.htm', 'https://btc.cryptoid.info/ion/address.dws?{0}.htm', 'https://chainz.cryptoid.info/ion/block.dws?{0}.htm', 9), + +(10, 'https://dashblockexplorer.com/', 'https://dashblockexplorer.com/tx/{0}', 'https://dashblockexplorer.com/address/{0}', 'https://dashblockexplorer.com/block/{0}', 8), + +(11, 'https://dogechain.info/', 'https://dogechain.info/tx/{0}', 'https://dogechain.info/address/{0}', 'https://dogechain.info/block/{0}', 10), + +(12, 'https://beaconcha.in/', 'https://beaconcha.in/tx/{0}', 'https://beaconcha.in/address/{0}', 'https://beaconcha.in/block/{0}', 11), + +(14, 'https://ethplorer.io/', 'https://etherscan.io/tx/{0}', 'https://etherscan.io/address/{0}', 'https://etherscan.io/block/{0}', 13), + +(15, 'https://polygonscan.com/', 'https://polygonscan.com/{0}', 'https://polygonscan.com/address/{0}', 'https://etherscan.io/token/{1}?a={0}', 'https://polygonscan.com/block/{0}', 14), + +(16, 'https://tronscan.org/#/', 'https://tronscan.org/#/transaction/{0}', 'https://tronscan.org/#/address/{0}', 'https://tronscan.org/#/block/{0}', 15), + diff --git a/database/transaction.sql b/database/transaction.sql index 8177658..06fc15f 100644 --- a/database/transaction.sql +++ b/database/transaction.sql @@ -1,9 +1,17 @@ CREATE SEQUENCE "transaction_id_seq" START 1; CREATE TABLE "transaction" ( - "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('transaction_id_seq'), - "hash" BYTEA NOT NULL, - "amount" NUMERIC(48,24), - "block_id" BIGINT NOT NULL, + "id" BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('transaction_id_seq'), + "hash" BYTEA NOT NULL, + "amount" NUMERIC(48,24), + "block_id" BIGINT NOT NULL, CONSTRAINT "fk__transaction__block" FOREIGN KEY ("block_id") REFERENCES "block" ("id") -); \ No newline at end of file +); + +-- INSERT INTO public.transaction( +-- hash, amount, block_id) +-- VALUES ('c13b2c9e1047cebc381d82a94b90a97853d0f0c711f83f2506697067a7245522'::bytea, 0.0000023, 1), +-- ('821d9d3394dd21ea1172f7772d7738f0a7b48f23bfe73a2966fe1eda57a677f3'::bytea, 0.000001, 2), +-- ('192b3ea24c63ed527d962ae92d699c70ead06c0d90265bb86db30177849c81f1'::bytea, 6264.29, 4), +-- ('d82fd5e6e25efd0a48f5115fa0161ca95647e8c2cde3375f9f03e9297974f557'::bytea, 32011.48, 5), +-- ('e494244c1e7f7357928284661f1c780ca301e2a5d24ec1b09409c98fcd28465e'::bytea, 88.888888, 3); \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 548419b..22d2bdd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,6 +9,7 @@ dependencies: shelf: ^1.2.0 shelf_router: ^1.0.0 shelf_static: ^1.0.0 + postgres: ^2.6.1 dev_dependencies: http: ^0.13.0