1 个不稳定版本

0.2.0 2023 年 1 月 24 日
0.1.0 2023 年 1 月 24 日

#11 in #account-id

MIT 许可证

175KB
4.5K SLoC


build PyPI version License: MIT Code style: black

Pyonear

pyonear 是 NEAR Rust API crate 的 Python 绑定。它提供了用于构建、签名和(反)序列化事务的快速且健壮的包装器。包装的类型来自 near-primitivesnear-cryptonear-vm-errors crate。

阅读文档

安装

pip install pyonear

示例用法

>>> from pyonear.crypto import InMemorySigner, KeyType
>>> from pyonear.account_id import AccountId
>>> from pyonear.crypto_hash import CryptoHash
>>> from pyonear.transaction import Transaction, TransferAction
>>> signer = InMemorySigner.from_random(AccountId("alice.near"), KeyType.ED25519)
>>> signer_id = AccountId("alice.near")
>>> signer = InMemorySigner.from_random(signer_id, KeyType.ED25519)
>>> public_key = signer.public_key
>>> nonce = 0
>>> receiver_id = AccountId("bob.near")
>>> block_hash = CryptoHash.default() # replace with a real blockhash
>>> actions = [TransferAction(1_000_000)]
>>> transaction = Transaction(signer_id, public_key, nonce, receiver_id, block_hash, actions).sign(signer)
>>> transaction.to_base64()
'CgAAAGFsaWNlLm5lYXIA++M56uPzUi8ezkHqJBLjc7ZCzJk88zoIpF5XkjUM13kAAAAAAAAAAAgAAABib2IubmVhcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAANAQg8AAAAAAAAAAAAAAAAAALK42W7t/vpUmDAgtChTUWEVvSE3cQZWRla8spN6KfNv9fWn16klROeblzH480b0a+NSL16YfnvWLnd2C9KLTQk='

开发

先决条件:Rust >= 1.65,Python >= 3.7,Poetry >= 1.1.14

步骤

  1. poetry install(仅执行一次)
  2. poetry shell
  3. maturin develop
  4. pytest
  5. makelint

依赖项

~38MB
~631K SLoC