Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create messages tables #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions migrations/clickhouse/000002_edit_validator_message.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE TABLE IF NOT EXISTS spacebox.edit_validator_message
(
`timestamp` DateTime,
`height` Int64,
`tx_hash` String,
`description` String
) ENGINE = MergeTree()
ORDER BY (`timestamp`, `height`, `tx_hash`);


CREATE MATERIALIZED VIEW IF NOT EXISTS spacebox.edit_validator_message_writer
TO spacebox.edit_validator_message AS
select
height,
`timestamp`,
txhash as tx_hash,
JSONExtractString(msg, 'description') as description
from (
select
*,
arrayJoin(JSONExtractArrayRaw(JSONExtractString(tx, 'body', 'messages'))) AS msg,
JSONExtractString(msg, '@type') AS type
from spacebox.raw_transaction
where type = '/cosmos.staking.v1beta1.MsgEditValidator' and code = 0
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE TABLE IF NOT EXISTS spacebox.cancel_unbonding_delegation_message
(
`timestamp` DateTime,
`height` Int64,
`tx_hash` String,
`delegator_address` String,
`validator_address` String
) ENGINE = MergeTree()
ORDER BY (`timestamp`, `height`, `tx_hash`, `delegator_address`, `validator_address`);

CREATE MATERIALIZED VIEW IF NOT EXISTS spacebox.cancel_unbonding_delegation_message_writer
TO spacebox.cancel_unbonding_delegation_message AS
select
height,
`timestamp`,
txhash as tx_hash,
JSONExtractString(msg, 'delegatorAddress') AS delegator_address,
JSONExtractString(msg, 'validatorAddress') AS validator_address
from (
select
*,
arrayJoin(JSONExtractArrayRaw(JSONExtractString(tx, 'body', 'messages'))) AS msg,
JSONExtractString(msg, '@type') AS type
from spacebox.raw_transaction
where type = '/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation' and code = 0
)
29 changes: 29 additions & 0 deletions migrations/clickhouse/000004_delegate_message.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CREATE TABLE IF NOT EXISTS spacebox.delegation_message
(
`timestamp` DateTime,
`operator_address` String,
`delegator_address` String,
`amount` String,
`height` Int64,
`tx_hash` String
) ENGINE = MergeTree()
ORDER BY (`operator_address`, `delegator_address`, `height`, `tx_hash`, `timestamp`);


CREATE MATERIALIZED VIEW IF NOT EXISTS spacebox.delegation_message_writer
TO spacebox.delegation_message AS
select
height,
`timestamp`,
txhash as tx_hash,
JSONExtractString(msg, 'delegatorAddress') as delegator_address,
JSONExtractString(msg, 'validatorAddress') as operator_address,
JSONExtractString(msg, 'amount') as amount
from (
select
*,
arrayJoin(JSONExtractArrayRaw(JSONExtractString(tx, 'body', 'messages'))) AS msg,
JSONExtractString(msg, '@type') AS type
from spacebox.raw_transaction
where type = '/cosmos.staking.v1beta1.MsgDelegate' and code = 0
)
34 changes: 34 additions & 0 deletions migrations/clickhouse/000005_create_validator_message.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CREATE TABLE IF NOT EXISTS spacebox.create_validator_message
(
`timestamp` DateTime
`height` Int64,
`tx_hash` String,
`delegator_address` String,
`validator_address` String,
`description` String,
`commission` String,
`min_self_delegation` Int64,
`pubkey` String
) ENGINE = MergeTree()
ORDER BY (`timestamp`, `height`, `tx_hash`, `delegator_address`, `validator_address`, `commission_rates` );

CREATE MATERIALIZED VIEW IF NOT EXISTS spacebox.create_validator_message_writer
TO spacebox.create_validator_message AS
select
height,
`timestamp`,
txhash as tx_hash,
JSONExtractString(msg, 'delegatorAddress') as delegator_address,
JSONExtractString(msg, 'validatorAddress') as validator_address,
JSONExtractString(msg, 'description') as description,
JSONExtractString(msg, 'commission') as commission,
JSONExtractString(msg, 'pubkey') as pubkey,
toInt64(JSONExtractString(msg, 'minSelfDelegation')) as min_self_delegation
from (
select
*,
arrayJoin(JSONExtractArrayRaw(JSONExtractString(tx, 'body', 'messages'))) AS msg,
JSONExtractString(msg, '@type') AS type
from spacebox.raw_transaction
where type = '/cosmos.staking.v1beta1.MsgCreateValidator' and code = 0
)
30 changes: 30 additions & 0 deletions migrations/clickhouse/000006_unbonding_delegation_message.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE TABLE IF NOT EXISTS spacebox.unbonding_delegation_message
(
`timestamp` DateTime
`operator_address` String,
`delegator_address` String,
`amount` String,
`completion_time` DateTime,
`height` Int64,
`tx_hash` String
) ENGINE = MergeTree()
ORDER BY (`timestamp`, `tx_hash`, `operator_address`, `delegator_address`, `completion_time`, `height`);

CREATE MATERIALIZED VIEW IF NOT EXISTS spacebox.unbonding_delegation_message_writer
TO spacebox.unbonding_delegation_message AS
select
height,
`timestamp`,
txhash as tx_hash,
JSONExtractString(msg, 'delegatorAddress') as delegator_address,
JSONExtractString(msg, 'validatorAddress') as operator_address,
JSONExtractString(msg, 'amount') as amount,
parseDateTimeBestEffort(JSONExtractString(arrayFilter(x -> JSONExtractString(x, 'key') = 'completion_time', JSONExtractArrayRaw(JSONExtractString(arrayFilter(x -> JSONExtractString(x, 'type') = 'unbond', JSONExtractArrayRaw(events))[1], 'attributes')))[1], 'value')) AS completion_time
from (
select
*,
arrayJoin(JSONExtractArrayRaw(JSONExtractString(tx, 'body', 'messages'))) AS msg,
JSONExtractString(msg, '@type') AS type
from spacebox.raw_transaction
where type = '/cosmos.staking.v1beta1.MsgUndelegate' and code = 0
)
32 changes: 32 additions & 0 deletions migrations/clickhouse/000007_begin_redelegate_message.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CREATE TABLE IF NOT EXISTS spacebox.redelegation_message
(
`delegator_address` String,
`src_validator_address` String,
`dst_validator_address` String,
`amount` String,
`height` Int64,
`completion_time` DateTime,
`tx_hash` String,
`timestamp` DateTime
) ENGINE = MergeTree()
ORDER BY (`delegator_address`, `src_validator_address`, `dst_validator_address`, `height`, `completion_time`, `tx_hash`, `timestamp`);

CREATE MATERIALIZED VIEW IF NOT EXISTS spacebox.redelegation_message_writer
TO spacebox.redelegation_message AS
select
height,
`timestamp`,
txhash as tx_hash,
JSONExtractString(msg, 'delegatorAddress') as delegator_address,
JSONExtractString(msg, 'validatorSrcAddress') as src_validator_address,
JSONExtractString(msg, 'validatorDstAddress') as dst_validator_address,
JSONExtractString(msg, 'amount') as amount,
parseDateTimeBestEffort(JSONExtractString(arrayFilter(x -> JSONExtractString(x, 'key') = 'completion_time', JSONExtractArrayRaw(JSONExtractString(arrayFilter(x -> JSONExtractString(x, 'type') = 'redelegate', JSONExtractArrayRaw(events))[1], 'attributes')))[1], 'value')) AS completion_time
from (
select
*,
arrayJoin(JSONExtractArrayRaw(JSONExtractString(tx, 'body', 'messages'))) AS msg,
JSONExtractString(msg, '@type') AS type
from spacebox.raw_transaction
where type = '/cosmos.staking.v1beta1.MsgBeginRedelegate' and code = 0
)
29 changes: 29 additions & 0 deletions migrations/clickhouse/000008_message.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CREATE TABLE IF NOT EXISTS spacebox.message
(
`timestamp` DateTime,
`transaction_hash` String,
`msg_index` Int64,
`type` String,
`signer` String,
`value` String
) ENGINE = MergeTree()
ORDER BY (`transaction_hash`, `type`, `timestamp`, `signer`);


CREATE MATERIALIZED VIEW IF NOT EXISTS spacebox.message_writer
TO spacebox.message AS
select
height,
`timestamp`,
type,
signer,
msg as value,
txhash as transaction_hash
from (
select
*,
arrayJoin(JSONExtractArrayRaw(JSONExtractString(tx, 'body', 'messages'))) AS msg,
JSONExtractString(msg, '@type') AS type
from spacebox.raw_transaction
where code = 0
)