Skip to content

Instantly share code, notes, and snippets.

View Mleekko's full-sized avatar

Oleh Koval Mleekko

View GitHub Profile
# 1. Transferring tokens from a running node
####
curl -s -u superadmin:$NGINX_SUPERADMIN_PASSWORD \
-X POST -k 'https://localhost/account' \
-H 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "account.submit_transaction_single_step",
"params": {
"actions": [
@Mleekko
Mleekko / MessageEncoder.java
Last active March 30, 2022 22:47
Encoding and Decoding messages in Radix transactions
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import java.nio.charset.StandardCharsets;
public class MessageEncoder {
public static String decode(String message) throws DecoderException {
if (message.startsWith("0000")) { // sent through new API
byte[] bytes = Hex.decodeHex(message.substring(4).toCharArray());
@Mleekko
Mleekko / RadixQueries.sql
Created February 9, 2022 23:13
Useful queries on `radix_ledger` DB
-- 1. Get balances of all accounts holding a token on a specific date
WITH new_year_state AS (
select state_version
from ledger_transactions
where round_timestamp < '2022-01-09 00:00:00'
order by round_timestamp desc
limit 1
)
Select last_transaction, address, balance from
(select lt.round_timestamp as last_transaction, abh.to_state_version, abh.from_state_version, address,
@Mleekko
Mleekko / KeyManager.java
Created March 30, 2022 23:07
KeyManager - manage multiple signing keys for Radix APIs.
import com.radixdlt.crypto.ECDSASignature;
import com.radixdlt.crypto.ECKeyPair;
import com.radixdlt.crypto.ECPublicKey;
import com.radixdlt.crypto.exception.PrivateKeyException;
import com.radixdlt.crypto.exception.PublicKeyException;
import com.radixdlt.identifiers.REAddr;
import com.radixdlt.networks.Addressing;
import com.radixdlt.networks.Network;
import com.radixdlt.utils.Bytes;
import lombok.extern.slf4j.Slf4j;
@Mleekko
Mleekko / query.sql
Last active June 27, 2022 00:11
Average balances per account
-- Average balances per account
WITH balances AS (
SELECT abh.balance as balance,
abh.account_id
FROM account_resource_balance_history abh
where abh.resource_id = 1 AND abh.to_state_version is null
),
staked_balances AS (
SELECT
account_id,
@Mleekko
Mleekko / query.sql
Created July 4, 2022 17:55
Validators that missed proposals recently
WITH validator_data AS (
SELECT t.validator_id, t.name
FROM public.validator_data_substates t
WHERE name IS NOT NULL
AND down_state_version IS NULL
ORDER BY t.validator_id
)
(SELECT k.epoch, '<- Current Epoch' as validator, Null as proposals_missed, Null as proposals_completed
FROM validator_proposal_records k