跳转到主要内容

Skycoin Python库

项目描述

PySkycoin

Build Status

Python扩展,用于访问Skycoin API。使用SWIG生成的Python扩展,用于从Python访问Skycoin API。

目录

安装

http://github.com/fibercrypto/pyskycoin.git下载存储库。执行(python setup.py install)以安装库。虽然执行(python setup.py develop)是修改库的更好选择。但是,当使用tox时,这些命令根本不需要,因为调用tox将执行必要的安装并运行测试。

用法

命名

PySkycoin导出的函数具有以下命名格式:SKY_package_func_name,其中package替换为原始Skycoin函数所在的包,func_name是函数的名称。例如,从cli包的LoadConfig函数在Python中调用为SKY_cli_LoadConfig

参数

所有skycoin导出函数都将错误对象作为最后一个返回参数。在Pyskycoin中,错误作为整数返回,它是第一个返回参数。其余参数按相同顺序返回。

在Skycoin中的接收器是输入参数中的第一个。简单的类型,如整数、浮点数、字符串,将用作Python中的对应类型。

句柄

一些Skycoin类型过于复杂,无法导出到脚本语言。因此,使用句柄代替。因此,所有接收复杂类型的函数都将接收句柄而不是原始的Skycoin类型。例如,以下这些函数是从Skycoin导出的

	func LoadConfig() (Config, error)
	func (c Config) FullWalletPath() string

Config是一个结构体类型,在Pyskycoin中被当作句柄处理。在Python中的使用方式为

import skycoin
	
def main:
	err, configHandle = skycoin.SKY_cli_LoadConfig()
	if err == skycoin.SKY_OK:  # 0 then no error
		fullWalletPath = skycoin.SKY_cli_FullWalletPath(configHandle)
		print fullWallerPath
		#Close the handle after using the it
		#so the garbage collector can delete the object associated with it. 
		skycoin.SKY_handle_close( configHandle )
	else: 
		#Error
		print err

字节切片

类型为byte[]的参数将被当作字符串处理。例如,Skycoin中的这个函数

func (s ScryptChacha20poly1305) Encrypt(data, password []byte) ([]byte, error)

将被调用为

encrypt_settings = skycoin.encrypt__ScryptChacha20poly1305()
data = "Data to encrypt" #It will be passed as a parameter of type []byte
pwd = "password"         #As []byte too
err, encrypted = skycoin.SKY_encrypt_ScryptChacha20poly1305_Encrypt(encrypt_settings, data, pwd)
if err == skycoin.SKY_OK:
	print encrypted #Encrypted is string

结构体

没有作为句柄导出的结构体在Python中就像类一样处理。在上一个例子中,类型ScryptChacha20poly1305在Python中创建如下

encrypt_settings = skycoin.encrypt__ScryptChacha20poly1305()

并在调用SKY_encrypt_ScryptChacha20poly1305_Encrypt时作为第一个参数传递。

固定大小数组

从Python调用时,固定大小数组的参数将被封装在结构体中。

给定这些在Skycoin中的类型

	type PubKey [33]byte
	type SecKey [32]byte

以及这个导出的函数

	func GenerateDeterministicKeyPair(seed []byte) (PubKey, SecKey)

在Python中的使用方式如下

#Generates random seed
err, data = skycoin.SKY_cipher_RandByte(32)
assert err == skycoin.SKY_OK
pubkey = skycoin.cipher_PubKey()
seckey = skycoin.cipher_SecKey()
err = skycoin.SKY_cipher_GenerateDeterministicKeyPair(data, pubkey, seckey)

pubkey和seckey是包含一个名为data字段的结构的对象,对应于PubKey和SecKey的类型。类似于

	cipher_PubKey struct{
		data [33]byte;
	} cipher_PubKey;

	cipher_SecKey struct{
		data [32]byte;
	} ;

其他切片

其他类型的切片被封装在类中。调用以下函数

func GenerateDeterministicKeyPairs(seed []byte, n int) []SecKey

将是这样的

#Generates random seed
err, seed = skycoin.SKY_cipher_RandByte(32)
err, seckeys = skycoin.SKY_cipher_GenerateDeterministicKeyPairs(seed, 2)
for seckey in seckeys:
	pubkey = skycoin.cipher_PubKey()
	skycoin.SKY_cipher_PubKeyFromSecKey(seckey, pubkey)
	err = skycoin.SKY_cipher_PubKey_Verify(pubkey)
	assert err == skycoin.SKY_OK

验证地址的示例

def addressIsValid(addr):
    addres = skycoin.cipher__Address()
    err = skycoin.SKY_cipher_DecodeBase58Address(addr, addres)
    return err != skycoin.SKY_OK

内存管理

内存管理对用户是透明的。在库中分配的任何对象都留给Python垃圾收集器管理。

制作规则

所有这些制作规则都需要skycoin是pyskycoin的git子模块

  • build-libc
    • 编译skycoin C语言库。
  • build-swig
    • 创建生成Python库的包装C代码。
  • develop
    • 安装模块的开发版本。
  • test
    • 编译skycoin C语言库,创建包装并执行Tox。Tox安装编译Python库并执行测试。

开发环境搭建

强烈建议开发者使用可用的Docker镜像来设置他们的环境。有关更多详细信息,请阅读PySkycoin Docker文档

该项目有两个分支:masterdevelop

  • develop是默认分支,并将始终包含最新的代码。位于gopath/src/github.com/fibercrypto/libskycoin的子模块必须与skycoin/skycoindevelop分支保持同步。
  • master将始终等于网站上当前稳定的版本,并且应该与最新的发布标签相对应。位于gopath/src/github.com/fibercrypto/libskycoin的子模块必须与skycoin/skycoinmaster分支保持同步。

将创建单独的稳定开发分支来为支持Skycoin的最新稳定版本制作发布。这些分支的名称应该是Skycoin的主版本和次要版本号,后跟dev后缀,例如0.25dev。这些分支可以从masterdevelop分支分叉出来,并且位于gopath/src/github.com/fibercrypto/libskycoin的子模块必须与官方存储库fibercrypto/libskycoin的相应标签保持同步。

创建稳定的开发分支通常有以下原因

  • Skycoin的发布增加了补丁版本号
  • 增强对使用Skycoin稳定版本编译的PySkycoin版本的支持和错误修复
  • 回滚到develop中添加的有用功能。

运行测试

$ make test

版本发布

更新版本

  1. 如果master分支有不在develop中的提交(例如,由于对master应用的热修复),则合并masterdevelop(并修复任何构建或测试失败)
  2. 切换到名为release-X.Y.Z的新发布分支,为发布做准备。
  3. 确保在gopath/src/github.com/fibercrypto/libskycoin的子模块与https://github.com/fibercrypto/libskycoin仓库中相应的标签保持同步。
  4. 更新skycoin/__init__.py中的__version__
  5. 运行make build以确保代码库是最新的。
  6. 更新CHANGELOG.md:将“未发布”的更改移动到版本,并添加日期。
  7. 按照预发布测试中的步骤进行。
  8. 制作一个将发布分支合并到master的PR。
  9. 审查PR并将其合并。
  10. 更新https://github.com/skycoin/repo-info/tree/master/repos/skycoin/remote中的文件,为simelotech/skycoindev-dotnet Docker镜像添加一个新文件,并调整可能已更改的任何配置文本。
  11. 使用版本号对master分支进行标记。版本标签以v开头,例如v0.20.0。对标签进行签名。如果您在github上有GPG密钥,在Github网站上创建发布将自动标记发布。您也可以使用git tag -as v0.20.0 $COMMIT_ID从命令行进行标记,但Github不会将其识别为“发布”。
  12. 由travis创建和上传发布构建。要手动执行,请检出master分支并按照创建发布构建说明进行操作。
  13. 检出develop分支并将__version__提升到下一个dev版本号

预发布测试

在发布前执行这些操作。

make test-ci

版本签名

发布使用此PGP密钥签名

0x5801631BD27C7874

此密钥的指纹是

pub   ed25519 2017-09-01 [SC] [expires: 2023-03-18]
      10A7 22B7 6F2F FE7B D238  0222 5801 631B D27C 7874
uid                      GZ-C SKYCOIN <token@protonmail.com>
sub   cv25519 2017-09-01 [E] [expires: 2023-03-18]

Keybase.io账号:https://keybase.io/gzc

备选签名密钥

Keybase.io账号:https://keybase.io/olemis

此密钥的指纹是

pub   rsa4096 2019-01-17 [SC] [expires: 2024-01-16]
uid           Olemis Lang <olemis@simelo.tech>
sub   rsa4096 2019-01-17 [E] [expires: 2024-01-16]

按照Tor项目的签名验证说明进行操作。

发布及其签名可在发布页面找到。

生成PGP密钥、发布它、签名标签和二进制的说明:https://gist.github.com/gz-c/de3f9c43343b2f1a27c640fe529b067c

创建发布构建

发布构建应从git标签创建。在更新发布版本后,必须遵循以下步骤

cd /path/to/pyskycoin
python3 setup.py sdist bdist_wheel
python3 -m pip install --user --upgrade twine
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

这会自动为travis-cicircle-ci执行。

为manylinux创建发布构建

发布构建应从git标签创建。在更新发布版本后,必须遵循以下步骤

对于64bits构建

cd /path/to/pyskycoin
make bdist_manylinux
python3 -m pip install --user --upgrade twine
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

32bits构建的情况下

cd /path/to/pyskycoin
make bdist_manylinux_i686
python3 -m pip install --user --upgrade twine
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

这是与skyapi相同的流程。

这将在travis-cicircle-ci中自动执行,即使有手动执行的选择,此过程也应自动执行。

Skycoin Api的Python封装

此包装器由openapi-generator直接从版本v0.25.1的Skycoin Api代码自动生成。

有关Python Skycoin Api包装器的进一步使用细节,请参阅自动生成文档

要使用特定于Skycoin api节点的包装器,只需执行以下操作

# create an instance of the Configuration class
configuration = skyapi.Configuration()
# set new host
configuration.host = 'some_host'

# create an instance of the API class with new configuration
api_instance = skyapi.DefaultApi(skyapi.ApiClient(configuration))

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

pyskyfiber-0.27.0.dev1.tar.gz (50.4 kB 查看散列)

上传于

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面