Skip to content

SDK API discussion #16

Open
Open
@vsbogd

Description

I have created this issue to discuss the API which should be provided by SDK for client development.
Currently implemented approach is to generate client API stubs on the fly when new client instance is created (see Usage section of the README.md).

Example I have posted below has two items which I would like to discuss:

  1. it contains some example of API which can be used to configure SingularityNet service interaction session
  2. it demonstrates client implementation when client stubs are generated in advance, before developing a client code.
import snet
import snet.example_service as example_service

# Define identity, ethereum endpoint, IPFS endpoint, session cache strategy
identity = snet.PrivateKeyIdentity("path/to/private/key") 
eth = snet.KovanEth()
ipfs = snet.SnetIpfs()
cache = snet.FileSystemSessionCache("path/to/cache/folder")
session = snet.Session(identity=identity, eth=eth, ipfs=ipfs, cache=cache)

# Check AGI tokens balance and MultiPartyEscrow contract balance of session
# identity, and deposit tokens to the MultiPartyEscrow.
print("AGI tokens available:", session.balance())
session.deposit(1000)
print("AGI tokens available:", session.balance())

# Instantiate "Example Service" client and call the method.
# example_service.Calculator is generated as prerequisite step, for example
# user calls `snet sdk` command providing org_id and service_id to generate
# snet.example_service package with all necessary stubs. All logic related to
# opening channel, finding proper endpoint, switching between endpoints is
# embedded into service stub.
example_service = example_service.Calculator(session)
numbers = example_service.Numbers(a=7, b=6)
result = example_service.mul(numbers)
print("Calculation result:", result.value)
print("AGI tokens available:", session.balance())

Item 2 is not so important probably for interpreted languages like Python or JavaScript but it can be faster and may be simpler than generating stubs on the fly. BTW it is harder to reuse such stubs in snet-cli so it is a bit contradicts to issue #9.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions