pg_cardano
Cardano相关工具包:加密函数,地址编解码,区块链处理
仓库
Fell-x27/pg_cardano
https://github.com/Fell-x27/pg_cardano
源码
pg_cardano-1.2.0.tar.gz
pg_cardano-1.2.0.tar.gz
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
pg_cardano | 1.2.0 | FEAT | MIT | Rust |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 2920 | pg_cardano | 否 | 是 | 否 | 是 | 否 | 否 | - |
| 相关扩展 | age hll rum pg_graphql pg_jsonschema jsquery pg_hint_plan hypopg |
|---|
PG18 fix by https://github.com/Vonng/pg_cardano
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.2.0 | 1817161514 | pg_cardano | - |
| RPM | PIGSTY | 1.2.0 | 1817161514 | pg_cardano_$v | - |
| DEB | PIGSTY | 1.2.0 | 1817161514 | postgresql-$v-pg-cardano | - |
构建
您可以使用 pig build 命令构建 pg_cardano 扩展的 RPM / DEB 包:
pig build pkg pg_cardano # 构建 RPM / DEB 包
安装
您可以直接安装 pg_cardano 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install pg_cardano; # 当前活跃 PG 版本安装
pig ext install -y pg_cardano -v 18 # PG 18
pig ext install -y pg_cardano -v 17 # PG 17
pig ext install -y pg_cardano -v 16 # PG 16
pig ext install -y pg_cardano -v 15 # PG 15
dnf install -y pg_cardano_18 # PG 18
dnf install -y pg_cardano_17 # PG 17
dnf install -y pg_cardano_16 # PG 16
dnf install -y pg_cardano_15 # PG 15
apt install -y postgresql-18-pg-cardano # PG 18
apt install -y postgresql-17-pg-cardano # PG 17
apt install -y postgresql-16-pg-cardano # PG 16
apt install -y postgresql-15-pg-cardano # PG 15
创建扩展:
CREATE EXTENSION pg_cardano;
用法
来源:README, Cargo.toml version 1.2.0
pg_cardano 是一个 Rust 扩展,为 PostgreSQL 提供面向 Cardano 的二进制与加密工具。上游仓库没有发布 GitHub release 或 tag,但默认分支当前 crate 版本是 1.2.0。
CREATE EXTENSION pg_cardano;
核心能力
- Base58 编码与解码。
- Bech32 编码与解码。
- CBOR 与
jsonb之间的双向转换,提供简单与扩展两套管线。 - Blake2b 哈希。
- Ed25519 签名与签名验证。
- CIP-105 与 CIP-129 的 dRep ID 辅助函数。
- Shelley 地址构造与解析。
- 资产名称解码与 CIP-88 pool key registration 验证。
常见模式
Base58 与 Bech32
SELECT cardano.base58_encode('Cardano'::bytea);
SELECT cardano.base58_decode('3Z6ioYHE3x');
SELECT cardano.bech32_encode('ada', 'is amazing'::bytea);
SELECT cardano.bech32_decode_prefix('ada1d9ejqctdv9axjmn8dypl4d');
SELECT cardano.bech32_decode_data('ada1d9ejqctdv9axjmn8dypl4d');
CBOR 转换
SELECT cardano.cbor_decode_jsonb('\xa3636164616b...'::bytea);
SELECT cardano.cbor_encode_jsonb('{"ada": "is amazing!", "bytes": "\\xdeadbeef"}'::jsonb);
SELECT cardano.cbor_decode_jsonb_ext('\xa3636164616b...'::bytea);
SELECT cardano.cbor_encode_jsonb_ext('{"type":"map","value":[...]}'::jsonb);
哈希与签名
SELECT cardano.blake2b_hash('Cardano is amazing!'::bytea, 32);
SELECT cardano.ed25519_verify_signature(
'\x432753BD...'::bytea,
'Cardano is amazing!'::bytea,
'\x74265f96...'::bytea
);
地址与治理辅助函数
SELECT cardano.tools_drep_id_encode_cip105('\x28111ae1...'::bytea, FALSE);
SELECT cardano.tools_drep_id_encode_cip129('\x28111ae1...'::bytea, TRUE);
SELECT cardano.tools_shelley_address_build(
'\x7415251f...'::bytea, FALSE,
'\x7c3ae2f2...'::bytea, FALSE,
0
);
SELECT cardano.tools_shelley_addr_get_type('addr_test1vp6p2fgl...');
注意事项
- 上游文档要求 PostgreSQL 12+,并通过
pgrx在 Linux 上构建;crate feature 当前面向 PostgreSQL 15 到 18,默认 feature 是pg18。 - 简单 CBOR 辅助函数会有意丢失部分 CBOR 结构信息;如果需要精确的结构往返,请使用
*_ext函数。