-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use COMDEX chain as base swapping main app for wasm app
Change docker image bases Change golang version Process Nyx chain cosmwasm transactions Add Nym specific tables Add module to hand-off message processing to an external API (Typescript + Express + postgres)
- Loading branch information
1 parent
28896c4
commit 77753d2
Showing
105 changed files
with
2,703 additions
and
1,552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.idea/ | ||
build/ | ||
pgdata | ||
|
||
# Configuration | ||
*.toml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
FROM golang:1.16-alpine AS builder | ||
RUN apk update && apk add --no-cache make git | ||
FROM golang:1.19-bullseye AS builder | ||
WORKDIR /go/src/github.com/forbole/bdjuno | ||
COPY . ./ | ||
RUN go mod download | ||
RUN make build | ||
RUN ldd build/bdjuno > /deps.txt | ||
RUN echo $(ldd build/bdjuno | grep libwasmvm.so | awk '{ print $3 }') | ||
|
||
FROM alpine:latest | ||
WORKDIR /bdjuno | ||
COPY --from=builder /go/src/github.com/forbole/bdjuno/build/bdjuno /usr/bin/bdjuno | ||
FROM debian:bullseye | ||
WORKDIR /root | ||
RUN apt-get update && apt-get install ca-certificates -y | ||
COPY --from=builder /deps.txt /root/deps.txt | ||
COPY --from=builder /go/pkg/mod/github.com/!cosm!wasm/[email protected]/api/libwasmvm.so /root | ||
COPY --from=builder /go/src/github.com/forbole/bdjuno/build/bdjuno /root/bdjuno | ||
ENV LD_LIBRARY_PATH=/root | ||
CMD [ "bdjuno" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package database | ||
|
||
import ( | ||
"fmt" | ||
dbtypes "github.com/forbole/bdjuno/v3/database/types" | ||
) | ||
|
||
// GetMessages returns all messages between block heights | ||
func (db *Db) GetMessages(address string, startHeight int64, endHeight int64, offset uint64, limit uint64) ([]dbtypes.MessageRow, error) { | ||
query := fmt.Sprintf(`SELECT | ||
transaction_hash, | ||
index, | ||
type, | ||
value, | ||
involved_accounts_addresses, | ||
height | ||
FROM message | ||
WHERE involved_accounts_addresses @> '{%s}' AND height >= %d AND height <= %d | ||
ORDER BY height ASC, type ASC, index ASC | ||
OFFSET %d LIMIT %d`, address, startHeight, endHeight, offset, limit) | ||
|
||
var dbRows []dbtypes.MessageRow | ||
err := db.Sqlx.Select(&dbRows, query) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return dbRows, nil | ||
} | ||
|
||
// GetMessagesCount returns count of GetMessages | ||
func (db *Db) GetMessagesCount(address string, startHeight int64, endHeight int64) (int, error) { | ||
|
||
stmt, err := db.Sqlx.Prepare(fmt.Sprintf(`SELECT count(height) | ||
FROM message | ||
WHERE involved_accounts_addresses @> '{%s}' AND height >= %d AND height <= %d`, address, startHeight, endHeight)) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
var count int | ||
err = stmt.QueryRow().Scan(&count) | ||
|
||
if err != nil { | ||
return 0, err | ||
} | ||
return count, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE TABLE wasm_execute_contract_event_types | ||
( | ||
contract_address TEXT NOT NULL REFERENCES wasm_contract (contract_address), | ||
event_type TEXT NOT NULL, | ||
|
||
first_seen_height BIGINT NOT NULL REFERENCES block (height), | ||
first_seen_hash TEXT NOT NULL, | ||
|
||
last_seen_height BIGINT NOT NULL REFERENCES block (height), | ||
last_seen_hash TEXT NOT NULL, | ||
UNIQUE (contract_address, event_type) | ||
); | ||
CREATE INDEX wasm_execute_contract_event_types_index ON wasm_execute_contract_event_types (contract_address, event_type); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
CREATE TABLE nyx_nym_mixnet_v1_mixnode | ||
( | ||
identity_key TEXT UNIQUE PRIMARY KEY, | ||
last_is_bonded_status BOOLEAN NULL, | ||
|
||
-- values: in_active_set, in_standby_set, inactive | ||
last_mixnet_status TEXT NULL | ||
); | ||
CREATE INDEX nyx_nym_mixnet_v1_mixnode_status_index ON nyx_nym_mixnet_v1_mixnode (last_mixnet_status); | ||
|
||
CREATE TABLE nyx_nym_mixnet_v1_mixnode_status | ||
( | ||
-- values: in_active_set, in_standby_set, inactive | ||
mixnet_status TEXT NOT NULL, | ||
|
||
-- in the range 0 to 100 | ||
routing_score INTEGER NOT NULL, | ||
|
||
identity_key TEXT NOT NULL REFERENCES nyx_nym_mixnet_v1_mixnode (identity_key), | ||
executed_at TIMESTAMP NOT NULL, | ||
height BIGINT NOT NULL REFERENCES block (height), | ||
hash TEXT NOT NULL | ||
); | ||
CREATE INDEX nyx_nm_v1_m_status_height_index ON nyx_nym_mixnet_v1_mixnode_status (height); | ||
CREATE INDEX nyx_nm_v1_m_identity_key_index ON nyx_nym_mixnet_v1_mixnode_status (identity_key); | ||
|
||
CREATE TABLE nyx_nym_mixnet_v1_mixnode_events | ||
( | ||
-- values: bond, unbond, delegate, undelegate, claim | ||
event_kind TEXT NOT NULL, | ||
-- values: mixnode_operator, mixnode_delegator, mixnet_rewarding, mixnet_monitoring | ||
actor TEXT NOT NULL, | ||
sender TEXT NOT NULL, | ||
proxy TEXT NULL, | ||
identity_key TEXT NOT NULL REFERENCES nyx_nym_mixnet_v1_mixnode (identity_key), | ||
executed_at TIMESTAMP NOT NULL, | ||
height BIGINT NOT NULL REFERENCES block (height), | ||
hash TEXT NOT NULL, | ||
message_index BIGINT NOT NULL | ||
); | ||
CREATE INDEX nyx_nm_v1_me_height_index ON nyx_nym_mixnet_v1_mixnode_events (identity_key, height); | ||
CREATE INDEX nyx_nm_v1_me_identity_key_executed_at_index ON nyx_nym_mixnet_v1_mixnode_events (identity_key, executed_at); | ||
|
||
CREATE TABLE nyx_nym_mixnet_v1_mixnode_reward | ||
( | ||
identity_key TEXT NOT NULL REFERENCES nyx_nym_mixnet_v1_mixnode (identity_key), | ||
total_node_reward COIN[] NOT NULL DEFAULT '{}', | ||
total_delegations COIN[] NOT NULL DEFAULT '{}', | ||
operator_reward COIN[] NOT NULL DEFAULT '{}', | ||
unit_delegator_reward BIGINT NOT NULL, | ||
apy FLOAT NOT NULL, | ||
executed_at TIMESTAMP NOT NULL, | ||
height BIGINT NOT NULL REFERENCES block (height), | ||
hash TEXT NOT NULL, | ||
message_index BIGINT NOT NULL, | ||
UNIQUE (identity_key, height, hash, message_index) | ||
); | ||
CREATE INDEX nyx_nm_v1_mr_height_index ON nyx_nym_mixnet_v1_mixnode_reward (height); | ||
CREATE INDEX nyx_nm_v1_mr_identity_key_index ON nyx_nym_mixnet_v1_mixnode_reward (identity_key); | ||
|
||
CREATE TABLE nyx_nym_mixnet_v1_gateway | ||
( | ||
identity_key TEXT UNIQUE PRIMARY KEY, | ||
last_is_bonded_status BOOLEAN NULL | ||
); | ||
|
||
CREATE TABLE nyx_nym_mixnet_v1_gateway_events | ||
( | ||
-- values: bond, unbond | ||
event_kind TEXT NOT NULL, | ||
sender TEXT NOT NULL, | ||
proxy TEXT NULL, | ||
identity_key TEXT NOT NULL REFERENCES nyx_nym_mixnet_v1_gateway (identity_key), | ||
executed_at TIMESTAMP NOT NULL, | ||
height BIGINT NOT NULL REFERENCES block (height), | ||
hash TEXT NOT NULL, | ||
message_index BIGINT NOT NULL | ||
); | ||
CREATE INDEX nyx_nm_v1_ge_height_index ON nyx_nym_mixnet_v1_gateway_events (identity_key, height); | ||
CREATE INDEX nyx_nm_v1_ge_identity_key_executed_at_index ON nyx_nym_mixnet_v1_gateway_events (identity_key, executed_at); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
CREATE TABLE nyx_nym_mixnet_v2_mixnode | ||
( | ||
mix_id BIGINT UNIQUE PRIMARY KEY, | ||
|
||
-- the identity key may be null, because a tx/event with only the mix_id might be processed out of order | ||
identity_key TEXT NULL, | ||
|
||
last_is_bonded_status BOOLEAN NULL, | ||
|
||
-- values: in_active_set, in_standby_set, inactive | ||
last_mixnet_status TEXT NULL | ||
); | ||
CREATE INDEX nyx_nm_v2_m_status_index ON nyx_nym_mixnet_v2_mixnode (last_mixnet_status); | ||
CREATE INDEX nyx_nm_v2_m_identity_key_index ON nyx_nym_mixnet_v2_mixnode (identity_key); | ||
|
||
CREATE TABLE nyx_nym_mixnet_v2_mixnode_status | ||
( | ||
-- values: in_active_set, in_standby_set, inactive | ||
mixnet_status TEXT NOT NULL, | ||
|
||
-- in the range 0 to 1 | ||
routing_score DECIMAL NOT NULL, | ||
|
||
mix_id BIGINT NOT NULL REFERENCES nyx_nym_mixnet_v2_mixnode (mix_id), | ||
executed_at TIMESTAMP NOT NULL, | ||
height BIGINT NOT NULL REFERENCES block (height), | ||
hash TEXT NOT NULL | ||
); | ||
CREATE INDEX nyx_nm_v2_ms_status_height_index ON nyx_nym_mixnet_v2_mixnode_status (height); | ||
CREATE INDEX nyx_nm_v2_ms_executed_at_index ON nyx_nym_mixnet_v2_mixnode_status (executed_at); | ||
|
||
CREATE TABLE nyx_nym_mixnet_v2_events | ||
( | ||
-- values: bond, unbond, delegate, undelegate, claim | ||
event_kind TEXT NOT NULL, | ||
-- values: mixnode_operator, mixnode_delegator, mixnet_rewarding, mixnet_monitoring, gateway_operator | ||
actor TEXT NOT NULL, | ||
sender TEXT NOT NULL, | ||
proxy TEXT NULL, | ||
mix_id BIGINT NULL REFERENCES nyx_nym_mixnet_v2_mixnode (mix_id), | ||
identity_key TEXT NOT NULL, | ||
executed_at TIMESTAMP NOT NULL, | ||
height BIGINT NOT NULL REFERENCES block (height), | ||
hash TEXT NOT NULL, | ||
message_index BIGINT NOT NULL | ||
); | ||
CREATE INDEX nyx_nm_v2_e_height_index ON nyx_nym_mixnet_v2_events (mix_id, height); | ||
CREATE INDEX nyx_nm_v2_e_executed_at_index ON nyx_nym_mixnet_v2_events (mix_id, executed_at); | ||
CREATE INDEX nyx_nm_v2_e_identity_key_executed_at_index ON nyx_nym_mixnet_v2_events (identity_key, executed_at); | ||
|
||
CREATE TABLE nyx_nym_mixnet_v2_mixnode_reward | ||
( | ||
mix_id BIGINT NOT NULL REFERENCES nyx_nym_mixnet_v2_mixnode (mix_id), | ||
operator_reward COIN[] NOT NULL DEFAULT '{}', | ||
delegates_reward COIN[] NOT NULL DEFAULT '{}', | ||
prior_delegates COIN[] NOT NULL DEFAULT '{}', | ||
prior_unit_reward BIGINT NOT NULL, | ||
apy FLOAT NOT NULL, | ||
epoch BIGINT NOT NULL, | ||
executed_at TIMESTAMP NOT NULL, | ||
height BIGINT NOT NULL REFERENCES block (height), | ||
hash TEXT NOT NULL, | ||
message_index BIGINT NOT NULL, | ||
UNIQUE (mix_id, height, hash, message_index) | ||
); | ||
CREATE INDEX nyx_nm_v2_mr_height_index ON nyx_nym_mixnet_v2_mixnode_reward (mix_id, height); | ||
CREATE INDEX nyx_nm_v2_mr_executed_at_index ON nyx_nym_mixnet_v2_mixnode_reward (mix_id, executed_at); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package types | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/lib/pq" | ||
) | ||
|
||
type MessageRow struct { | ||
TxHash string `db:"transaction_hash"` | ||
Index int `db:"index"` | ||
Type string `db:"type"` | ||
Value string `db:"value"` | ||
Aliases pq.StringArray `db:"involved_accounts_addresses"` | ||
Height int64 `db:"height"` | ||
} | ||
|
||
type MessageWithValueRow struct { | ||
TxHash string `json:"transaction_hash"` | ||
Index int `json:"index"` | ||
Type string `json:"type"` | ||
Value interface{} `json:"value"` | ||
Funds interface{} `json:"funds"` | ||
Aliases pq.StringArray `json:"involved_accounts_addresses"` | ||
Height int64 `json:"height"` | ||
} | ||
|
||
func NewMessageWithValueRow(row MessageRow) (*MessageWithValueRow, error) { | ||
var value map[string]interface{} | ||
err := json.Unmarshal([]byte(row.Value), &value) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var funds interface{} | ||
|
||
if value["funds"] != nil { | ||
funds = value["funds"] | ||
} | ||
if value["amount"] != nil { | ||
funds = value["amount"] | ||
} | ||
|
||
var rowWithValue = MessageWithValueRow{ | ||
TxHash: row.TxHash, | ||
Index: row.Index, | ||
Type: row.Type, | ||
Value: value, | ||
Funds: funds, | ||
Aliases: row.Aliases, | ||
Height: row.Height, | ||
} | ||
|
||
return &rowWithValue, nil | ||
} |
Oops, something went wrong.