光纤SDK

fabricasdk的Python项目详细描述


安装

fabrica sdk可以直接从pypi安装,其功能如下:

pip install fabricasdk

配置

fabrica sdk使用一个配置文件来确定在调用sdk方法时应使用哪个网络、网络设置和帐户。

下面是使用Rinkeby测试网络的配置文件的示例。

#rinkeby-config.json

{
  "private_key":"<user_private_key>",
  "cosigner_address": "<cosigner_address",
  "fabrica_api_url": "https://4hcsqf7aw0.execute-api.us-west-1.amazonaws.com/production",
  "fabrica_api_key": "hMieYmc2ewr@#E2!c8==3evb",
  "ipfs_endpoint": null,
  "ipfs_port": null,
  "network_url": "https://rinkeby.infura.io/j0RAOpI99Wf54yIYxNB6",
  "local_state_path": null
}

config参数

private_key:默认为none,表示发送方的私钥;如果此参数为none,则将使用transact方法而不是签名的sendrawtransaction调用所有协定函数。这个地址/私钥应该被认为是sdk的主要用户。

cosigner_address: 默认为无,表示联署人的公共eth地址。此地址应该不同于与上面的私钥关联的地址。

fabrica_api_url:默认为none,表示fabrica api的url

fabrica_api_key:默认为none,表示fabrica api密钥

ipfs_endpoint:默认为https://ipfs.infura.io

ipfs_port:默认为5001

network_url:默认为http://localhost:8545表示要使用的区块链网络;

local_state_path:默认为~/fabrica-state.db,表示本地状态文件的路径,如果没有向sdk构造函数提供状态插件,则将使用该路径。 ` 要使用上述配置文件实例化sdk,可以执行以下操作:

from fabricasdk import FabricaSdk

fabrica = FabricaSdk(os.path.join(dirname, "rinkeby-config.json"))

多尺寸钱包概述

fabrica sdk可以与单个以太坊帐户的私钥/公钥对一起使用,也可以与sdk生成的多sig钱包一起使用。在执行交易前,Multisig钱包需要从3个以太坊账户中的2个进行签名。

典型的多功能钱包由以下三个签名者组成:

  1. 最好将user_address视为sdk用户地址。

  2. 最初将成为fabrica地址的cosigner_address

  3. 代表最终用户帐户地址的customer_address

在上述配置文件中指定了sender_addresscosigner_address

要为新用户生成MultiSig钱包,您必须执行以下操作:

from fabricasdk import FabricaSdk

fabrica = FabricaSdk(os.path.join(dirname, "rinkeby-config.json"))

customer_address = "0x94bebe960a5de83911e901b309bd7dfb1cd7a679"

# multisig wallet created here

receipt = fabrica.factory.create(customer_address)

print(receipt)

多sig事务与非多sig事务

fabrica sdk中的所有核心方法都可以通过multisig钱包或“非multisig”钱包调用。如果您选择不使用multisig钱包,则sdk将尝试使用指定的配置文件sender_addressprivate_key执行事务。

fabrica sdk中的所有核心方法都接受可选参数cosigncustomer_address。默认情况下cosign=True。当cosign=True时,您还必须包括customer_address,这是与multsig wallet的三个签名者中的一个用户关联的公共帐户。

示例:

from fabricasdk import FabricaSdk

fabrica = FabricaSdk(os.path.join(dirname, "rinkeby-config.json"))

token_id = int(time.time())

customer_address = "0x94bebe960a5de83911e901b309bd7dfb1cd7a679"

# mints a token using a multisig wallet associated with the customer_address

fabrica.token.mint(token_id, "geoHash", "holdingEntity", "ipfs:/ipfs/whatever", customer_address=customer_address)

# mints a token using the sender_address and private_key specified in the config file

fabrica.token.mint(token_id, "geoHash", "holdingEntity", "ipfs:/ipfs/whatever", cosign=False)

使用mint方法创建标记元数据

与fabrica令牌关联的元数据存储在json对象中。Fuffa SDK MIt函数允许您传递用于创建元数据对象的值字典,该元数据对象存储在IPFS上并从令牌引用,或者将URL传递给指向现有元数据对象的方法或。

下面是使用a)值字典和b)元数据url生成令牌的示例

from fabricasdk import FabricaSdk

fabrica = FabricaSdk(os.path.join(dirname, "rinkeby-config.json"))

token_id = int(time.time())

# mint a token passing a dictionary of values to create a metadata object

receipt = fabrica.token.mint(
      token_id,
      "geoHash",
      "holdingEntity",
      {"name": "this is the name", "description": "this is the description"},
      cosign=bool(customer_address),
      customer_address=customer_address
  )

# mint a token passing a dictionary of values to create a metadata object including legal document creation (final legal document values TBD)

receipt = fabrica.token.mint(
      token_id,
      "geoHash",
      "holdingEntity",
      {
          "name": "this is the name",
          "description": "this is the description",
          "document": {
              "day": "19",
              "month": "08",
              "year": "2018",
              "grantor": "Steven Smith",
              "entity_id": "321123",
              "smartcontract_address": "0x00202020202",
              "property_legal_description": "this is a cool house",
              "trustee": "John Smith",
              "county": "Orange"
          }

      },
      cosign=bool(customer_address),
      customer_address=customer_address
  )




# mint a token using a URL that points to an existing metadata object

receipt = fabrica.token.mint(token_id, "geoHash", "holdingEntity", "ipfs:/ipfs/QmaFWUrRKHbNqKcZfUmnVMB38sb8XWJiJ27S5vH1NsaEai", customer_address=customer_address)

get_token()方法可用于验证和查看刚刚创建的令牌

示例:

from fabricasdk import FabricaSdk

fabrica = FabricaSdk(os.path.join(dirname, "rinkeby-config.json"))

print(fabrica.token.get_token("1"))

返回值应包括存储在智能合约中的核心令牌数据和相关元数据。

示例:

{'token_id': 1, 'geohash': '9q8zn2ez3uev', 'holding_entity': 'Fabrica 1', 'token_uri': 'https://ipfs.io/ipfs/Qmbh7EHR9EfPdWfwWB6tuKXjSGHWzVX36kp6e3TNmMfX3M', 'metadata': {'name': '1707 Jones Street', 'description': 'awesome property', 'formationDocURI': 'https://ipfs.io/ipfs/QmRnE2rQqKdE2Zus59ourBuEKy3BtHg7SYf9wyi9QdTnN8'}}

使用非multisig

下面是如何使用sdk执行以下基本功能的示例:生成令牌、更新令牌和在不使用multisig钱包的情况下传输令牌。

#minting a token

#create a unique token id
token_id = int(time.time())

customer_address = "0x94bebe960a5de83911e901b309bd7dfb1cd7a679"


#call the mint method of the SDK with a token id, geohash(string), holding entity(string), tokenuri (string)

#NOTE: the tokenURI points to a metadata object for the property(address, legal description and link to the formation legal document). Creation of the metadata object will be included in the next version of the SDK, along with conversion of lat/lng geocords to geohash.

receipt = fabrica.token.mint(token_id, "geoHash", "holdingEntity", "ipfs:/ipfs/whatever", cosign=False)

#verify that the token was successfully minted
token = fabrica.get_token(token_id)
print("token: {}".format(token))

#call the update method of the SDK with a token id, holding entity (string), and tokenuri (string)

receipt = fabrica.token.update_token(token_id, "otherEntity", "otherUri", cosign=False)
print(receipt)

#verify that the token was successfully updated
token = fabrica.token.get_token(token_id)
print("token: {}".format(token))

#call the transfer_from method of the SDK with the address of the existing token holder(your address), the address that you are sending the token to and the token_idself.

receipt = fabrica.token.transfer_from(<from_address>, <to_address>, token_id, cosign=False)
print(receipt)

token=fabrica.token.get_token(token_id)
print("token: {}".format(token))

使用multisig

下面是如何使用sdk执行以下基本功能的示例:创建令牌、更新令牌和tr用多功能钱包(包括创建多功能钱包)转送代币。

#minting a token

#create a unique token id
token_id = int(time.time())

#set customer address. note: this should be a valid ethereum address

customer_address = "0x94bebe960a5de83911e901b309bd7dfb1cd7a679"

#create multisig wallet

receipt = fabrica.factory.create(customer_address)

print(receipt)


#call the mint method of the SDK using cosign with a token id, geohash(string), holding entity(string), tokenuri (string)

#NOTE: the tokenURI points to a metadata object for the property(address, legal description and link to the formation legal document). Creation of the metadata object will be included in the next version of the SDK, along with conversion of lat/lng geocords to geohash.

receipt = fabrica.token.mint(token_id, "geoHash", "holdingEntity", "ipfs:/ipfs/whatever", customer_address=customer_address )

#verify that the token was successfully minted
token = fabrica.get_token(token_id)
print("token: {}".format(token))

#call the update method of the SDK using cosign with a token id, holding entity (string), and tokenuri (string)

receipt = fabrica.token.update_token(token_id, "otherEntity", "otherUri", customer_address=customer_address)
print(receipt)

#verify that the token was successfully updated
token = fabrica.token.get_token(token_id)
print("token: {}".format(token))

#call the transfer_from method of the SDK using cosign with the address of the existing token holder(your address), the address that you are sending the token to and the token_idself.

receipt = fabrica.token.transfer_from(<from_address>, <to_address>, token_id, customer_address=customer_address)
print(receipt)

token=fabrica.token.get_token(token_id)
print("token: {}".format(token))

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Grid loadmask(true)在gxt中不起作用   java将字符串索引转换为整数   为什么Java泛型适用于基元数组,但不适用于基元数组?   java如何让Azure应用程序服务Tomcat将所有80/443流量转发到运行在同一应用程序服务上的JBoss   具有多个值的java转换映射到树?   java如何设置SQL server连接URL?   java设置了多个相互独立的JFrame   安全性在JAVA中如何使用RSAPrivateKey的密码短语?   java不能使用比Apache Velocity中更大的条件   如何在Java中打印字符串的所有排列   停止Android Studio自动导入java。sql。日期   对象简单计算器程序java   java如何在安卓中使用“&”符号作为字符串?   java Connect,为我的安卓应用程序从REST API发布和获取数据