Giter VIP home page Giter VIP logo

ontology-go-sdk's Introduction

Go SDK For Ontology

1. Overview

This is a comprehensive Go library for the Ontology blockchain. Currently, it supports local wallet management, digital asset management, deployment/invoking of smart contracts and communication with the Ontology Blockchain. In the future it will also support more rich functions and applications.

2. How to use?

First, create an OntologySDK instance with the NewOntologySdk method.

ontSdk := NewOntologySdk()

Next, create an rpc, rest or websocket client.

ontSdk.NewRpcClient().SetAddress("http://localhost:20336")

Then, call the rpc server through the sdk instance.

2.1 Block Chain API

2.1.1 Get current block height

ontSdk.GetCurrentBlockHeight() (uint32, error)

2.1.2 Get current block hash

ontSdk.GetCurrentBlockHash() (common.Uint256, error)

2.1.3 Get block by height

ontSdk.GetBlockByHeight(height uint32) (*types.Block, error)

2.1.4 Get block by hash

ontSdk.GetBlockByHash(blockHash string) (*types.Block, error)

2.1.5 Get transaction by transaction hash

ontSdk.GetTransaction(txHash string) (*types.Transaction, error)

2.1.6 Get block hash by block height

ontSdk.GetBlockHash(height uint32) (common.Uint256, error)

2.1.7 Get block height by transaction hash

ontSdk.GetBlockHeightByTxHash(txHash string) (uint32, error)

2.1.8 Get transaction hashes of block by block height

ontSdk.GetBlockTxHashesByHeight(height uint32) (*sdkcom.BlockTxHashes, error)

2.1.9 Get storage value of smart contract key

ontSdk.GetStorage(contractAddress string, key []byte) ([]byte, error)

2.1.10 Get smart contract by contract address

ontSdk.GetSmartContract(contractAddress string) (*sdkcom.SmartContract, error)

2.1.11 Get smart contract event by transaction hash

ontSdk.GetSmartContractEvent(txHash string) (*sdkcom.SmartContactEvent, error)

2.1.12 Get all of smart contract events of block by block height

ontSdk.GetSmartContractEventByHeight(height uint32) ([]*sdkcom.SmartContactEvent, error)

2.1.13 Get block merkle proof by transaction hash

ontSdk.GetMerkleProof(txHash string) (*sdkcom.MerkleProof, error)

2.1.14 Get transaction state of transaction pool

ontSdk.GetMemPoolTxState(txHash string) (*sdkcom.MemPoolTxState, error)

2.1.15 Get transaction count in transaction pool

ontSdk.GetMemPoolTxCount() (*sdkcom.MemPoolTxCount, error)

2.1.16 Get version of Ontology

ontSdk.GetVersion() (string, error)

2.1.17 Get network id of Ontology

ontSdk.GetNetworkId() (uint32, error)

2.1.18 Send transaction to Ontology

ontSdk.SendTransaction(mutTx *types.MutableTransaction) (common.Uint256, error)

2.19 Prepare execute transaction

ontSdk.PreExecTransaction(mutTx *types.MutableTransaction) (*sdkcom.PreExecResult, error)

2.2 Wallet API

2.2.1 Create or Open Wallet

wa, err := OpenWallet(path string) (*Wallet, error)

If the path is for an existing wallet file, then open the wallet, otherwise return error.

2.2.2 Save Wallet

wa.Save() error

Note that any modifications of the wallet require calling Save() in order for the changes to persist.

2.2.3 New account

wa.NewAccount(keyType keypair.KeyType, curveCode byte, sigScheme s.SignatureScheme, passwd []byte) (*Account, error)

Ontology supports three type of keys: ecdsa, sm2 and ed25519, and support 224, 256, 384, 521 bits length of key in ecdsa, but only support 256 bits length of key in sm2 and ed25519.

Ontology support multiple signature scheme.

For ECDSA support SHA224withECDSA, SHA256withECDSA, SHA384withECDSA, SHA512withEdDSA, SHA3-224withECDSA, SHA3-256withECDSA, SHA3-384withECDSA, SHA3-512withECDSA, RIPEMD160withECDSA;

For SM2 support SM3withSM2, and for SHA512withEdDSA.

2.2.4 New default setting account

wa.NewDefaultSettingAccount(passwd []byte) (*Account, error)

The default settings for an account uses ECDSA with SHA256withECDSA as signature scheme.

2.2.5 New account from wif private key

wa.NewAccountFromWIF(wif, passwd []byte) (*Account, error)

2.2.5 Delete account

wa.DeleteAccount(address string) error

2.2.5 Get default account

wa.GetDefaultAccount(passwd []byte) (*Account, error)

2.2.6 Set default account

wa.SetDefaultAccount(address string) error

2.2.7 Get account by address

wa.GetAccountByAddress(address string, passwd []byte) (*Account, error)

2.2.8 Get account by label

wa.GetAccountByLabel(label string, passwd []byte) (*Account, error)

2.2.9 Get account by index

wa.GetAccountByIndex(index int, passwd []byte) (*Account, error)

Note that indexes start from 1.

2.2.10 Get account count of wallet

wa.GetAccountCount() int

2.2.11 Get default account data

wa.GetDefaultAccountData() (*AccountData, error)

2.2.12 Get account data by address

wa.GetAccountDataByAddress(address string) (*AccountData, error)

2.2.13 Get account data by label

wa.GetAccountDataByLabel(label string) (*AccountData, error)

2.2.14 Get account data by index

wa.GetAccountDataByIndex(index int) (*AccountData, error)

Note that indexes start from 1.

2.2.15 Set account label

wa.SetLabel(address, newLabel string) error

Note that label cannot duplicate.

2.2.16 Set signature scheme of account

wa.SetSigScheme(address string, sigScheme s.SignatureScheme) error

2.2.17 Change account password

wa.ChangeAccountPassword(address string, oldPassword, newPassword []byte) error

2.2.18 Import account to wallet

wa.ImportAccounts(accountDatas []*AccountData, passwds [][]byte) error

2.2.19 Export account to a new wallet

wa.ExportAccounts(path string, accountDatas []*AccountData, passwds [][]byte, newScrypts ...*keypair.ScryptParam) (*Wallet, error)

2.3 ONT Contract API

2.3.1 Get balance

ontSdk.Native.Ont.BalanceOf(address common.Address) (uint64, error)

2.3.2 Transfer

ontSdk.Native.Ont.Transfer(gasPrice, gasLimit uint64, from *Account, to common.Address, amount uint64) (common.Uint256, error)

2.3.3 Multiple Transfer

ontSdk.Native.Ont.MultiTransfer(gasPrice, gasLimit uint64, states []*ont.State, signer *Account) (common.Uint256, error)

A multi transfer does more than one transfer of ONT in one transaction.

2.3.4 Approve

ontSdk.Native.Ont.Approve(gasPrice, gasLimit uint64, from *Account, to common.Address, amount uint64) (common.Uint256, error)

2.3.5 Approve Balance

ontSdk.Native.Ont.Allowance(from, to common.Address) (uint64, error)

2.3.6 TransferFrom

ontSdk.Native.Ont.TransferFrom(gasPrice, gasLimit uint64, sender *Account, from, to common.Address, amount uint64) (common.Uint256, error)

2.3.7 Get balance V2

ontSdk.Native.Ont.BalanceOfV2(address common.Address) (*big.Int, error)

2.3.8 Transfer V2

ontSdk.Native.Ont.TransferV2(gasPrice, gasLimit uint64, from *Account, to common.Address, amount *big.Int) (common.Uint256, error)

2.3.9 Multiple Transfer V2

ontSdk.Native.Ont.MultiTransferV2(gasPrice, gasLimit uint64, states []*ont.State, signer *Account) (common.Uint256, error)

A multi transfer does more than one transfer of ONT in one transaction.

2.3.10 Approve V2

ontSdk.Native.Ont.ApproveV2(gasPrice, gasLimit uint64, from *Account, to common.Address, amount *big.Int) (common.Uint256, error)

2.3.11 Allowance V2

ontSdk.Native.Ont.AllowanceV2(from, to common.Address) (*big.Int, error)

2.3.12 Transfer From V2

ontSdk.Native.Ont.TransferFromV2(gasPrice, gasLimit uint64, sender *Account, from, to common.Address, amount *big.Int) (common.Uint256, error)

2.4 ONG Contract API

2.4.1 Get balance

ontSdk.Native.Ong.BalanceOf(address common.Address) (uint64, error)

2.4.2 Transfer

ontSdk.Native.Ong.Transfer(gasPrice, gasLimit uint64, from *Account, to common.Address, amount uint64) (common.Uint256, error)

2.4.3 Multiple Transfer

ontSdk.Native.Ong.MultiTransfer(gasPrice, gasLimit uint64, states []*ont.State, signer *Account) (common.Uint256, error)

A multi transfer does more than one transfer of ONG in one transaction.

2.4.4 Approve

ontSdk.Native.Ong.Approve(gasPrice, gasLimit uint64, from *Account, to common.Address, amount uint64) (common.Uint256, error)

2.4.5 Approve Balance

ontSdk.Native.Ong.Allowance(from, to common.Address) (uint64, error)

2.4.6 TransferFrom

ontSdk.Native.Ong.TransferFrom(gasPrice, gasLimit uint64, sender *Account, from, to common.Address, amount uint64) (common.Uint256, error)

2.4.7 Withdraw ONG

ontSdk.Native.Ong.WithdrawONG(gasPrice, gasLimit uint64, address *Account, amount uint64) (common.Uint256, error)

2.4.8 Get unbound ONG

ontSdk.Native.Ong.UnboundONG(address common.Address) (uint64, error)

2.4.9 Get balance V2

ontSdk.Native.Ong.BalanceOfV2(address common.Address) (*big.Int, error)

2.4.10 Transfer V2

ontSdk.Native.Ong.TransferV2(gasPrice, gasLimit uint64, from *Account, to common.Address, amount *big.Int) (common.Uint256, error)

2.4.11 Multiple Transfer V2

ontSdk.Native.Ong.MultiTransferV2(gasPrice, gasLimit uint64, states []*ont.State, signer *Account) (common.Uint256, error)

A multi transfer does more than one transfer of ONG in one transaction.

2.4.12 Approve V2

ontSdk.Native.Ong.ApproveV2(gasPrice, gasLimit uint64, from *Account, to common.Address, amount *big.Int) (common.Uint256, error)

2.4.13 Approve Balance V2

ontSdk.Native.Ong.AllowanceV2(from, to common.Address) (*big.Int, error)

2.4.14 TransferFrom V2

ontSdk.Native.Ong.TransferFrom(gasPrice, gasLimit uint64, sender *Account, from, to common.Address, amount *big.Int) (common.Uint256, error)

2.4.15 Withdraw ONG V2

ontSdk.Native.Ong.WithdrawONG(gasPrice, gasLimit uint64, address *Account, amount *big.Int) (common.Uint256, error)

2.4.16 Get unbound ONG V2

ontSdk.Native.Ong.UnboundONGV2(address common.Address) (*big.Int, error)

2.5 ONT ID API

2.5.1 RegID With PublicKey

ontSdk.Native.OntId.RegIDWithPublicKey(gasPrice, gasLimit uint64, payer *Account, ontId string, signer *Account) (common.Uint256, error)

ontId: registered ONT ID

signer: public key of ONT ID and signer account

2.5.2 RegID With Controller

ontSdk.Native.OntId.RegIDWithController(gasPrice, gasLimit uint64, payer *Account, ontId string, controller *ontid.Group, signers []ontid.Signer, controllerSigners []*Account) (common.Uint256, error)

ontId: registered ONT ID

controller:a group of ONT ID

signers: signer ONT IDs and its key index

controllerSigners: signer accounts

2.5.3 Revoke ID

ontSdk.Native.OntId.RevokeID(gasPrice, gasLimit uint64, payer *Account, ontId string, index uint32, signer *Account) (common.Uint256, error)

ontId: revoked ONT ID

index: key index of ONT ID

signer: signer account

2.5.4 Revoke ID By Controller

ontSdk.Native.OntId.RevokeIDByController(gasPrice, gasLimit uint64, payer *Account, ontId string, signers []ontid.Signer, controllerSigners []*Account) (common.Uint256, error)

ontId: revoked ONT ID

signers: signer ONT IDs and its key index

controllerSigners: signer accounts

2.5.5 Remove Controller

ontSdk.Native.OntId.RemoveController(gasPrice, gasLimit uint64, payer *Account, ontId string, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

index: key index of ONT ID

signer: signer account

2.5.6 RegID With Attributes

ontSdk.Native.OntId.RegIDWithAttributes(gasPrice, gasLimit uint64, payer *Account, ontId string, attributes []*DDOAttribute, signer *Account) (common.Uint256, error)

ontId: registered ONT ID

attributes: attributes of ONT ID

signer: public key of ONT ID and signer account

2.5.7 Add Key

ontSdk.Native.OntId.AddKey(gasPrice, gasLimit uint64, payer *Account, ontId string, newPubKey []byte, controller string, signer *Account) (common.Uint256, error)

ontId: ONT ID

newPubKey: new public key added

controller: controller ONT ID of this public key

signer: public key of ONT ID and signer account

2.5.8 Add Key By Index

ontSdk.Native.OntId.AddKeyByIndex(gasPrice, gasLimit uint64, payer *Account, ontId string, newPubKey []byte, index uint32, controller string, signer *Account) (common.Uint256, error)

ontId: ONT ID

newPubKey: new public key added

index: key index of ONT ID

controller: controller ONT ID of this public key

signer: signer account

2.5.9 Remove Key

ontSdk.Native.OntId.RemoveKey(gasPrice, gasLimit uint64, payer *Account, ontId string, removedPubKey []byte, signer *Account) (common.Uint256, error)

ontId: ONT ID

removedPubKey: public key removed

signer: public key of ONT ID and signer account

2.5.10 Remove Key By Index

ontSdk.Native.OntId.RemoveKeyByIndex(gasPrice, gasLimit uint64, payer *Account, ontId string, removedPubKey []byte, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

removedPubKey: public key removed

index: key index of ONT ID

signer: signer account

2.5.11 Set Recovery

ontSdk.Native.OntId.SetRecovery(gasPrice, gasLimit uint64, payer *Account, ontId string, recovery *ontid.Group, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

recovery: group of recovery of ONT ID

index: key index of ONT ID

signer: signer account

2.5.12 Update Recovery

ontSdk.Native.OntId.UpdateRecovery(gasPrice, gasLimit uint64, payer *Account, ontId string, newRecovery *ontid.Group, signers []ontid.Signer, recoverySigners []*Account) (common.Uint256, error)

ontId: ONT ID

newRecovery: new group of recovery of ONT ID

signers: signer ONT IDs and its key index

recoverySigners: signer accounts

2.5.13 Remove Recovery

ontSdk.Native.OntId.RemoveRecovery(gasPrice, gasLimit uint64, payer *Account, ontId string, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

index: key index of ONT ID

signer: signer account

2.5.14 AddKey By Controller

ontSdk.Native.OntId.AddKeyByController(gasPrice, gasLimit uint64, payer *Account, ontId string, publicKey []byte, signers []ontid.Signer, controller string, controllerSigners []*Account) (common.Uint256, error)

ontId: ONT ID

publicKey: new public key of ONT ID

signers: signer ONT IDs and its key index

controller: controller ONT ID of this public key

controllerSigners: signer accounts

2.5.15 RemoveKey By Controller

ontSdk.Native.OntId.RemoveKeyByController(gasPrice, gasLimit uint64, payer *Account, ontId string, publicKeyIndex []byte, signers []ontid.Signer, controllerSigners []*Account) (common.Uint256, error)

ontId: ONT ID

publicKeyIndex: public key index of ONT ID removed

signers: signer ONT IDs and its key index

controllerSigners: signer accounts

2.5.16 AddKey By Recovery

ontSdk.Native.OntId.AddKeyByRecovery(gasPrice, gasLimit uint64, payer *Account, ontId string, publicKey []byte, signers []ontid.Signer, controller string, recoverySigners []*Account) (common.Uint256, error)

ontId: ONT ID

publicKey: new public key of ONT ID

signers: signer ONT IDs and its key index

controller: controller ONT ID of this public key

recoverySigners: signer accounts

2.5.17 RemoveKey By Recovery

ontSdk.Native.OntId.RemoveKeyByRecovery(gasPrice, gasLimit uint64, payer *Account, ontId string, publicKeyIndex uint32, signers []ontid.Signer, recoverySigners []*Account) (common.Uint256, error)

ontId: ONT ID

publicKeyIndex: public key index of ONT ID removed

signers: signer ONT IDs and its key index

recoverySigners: signer accounts

2.5.18 Add Attributes

ontSdk.Native.OntId.AddAttributes(gasPrice, gasLimit uint64, payer *Account, ontId string, attributes []*DDOAttribute, signer *Account) (common.Uint256, error)

ontId: ONT ID

attributes: attributes of ONT ID

signer: public key of ONT ID and signer account

2.5.19 Add Attributes By Index

ontSdk.Native.OntId.AddAttributesByIndex(gasPrice, gasLimit uint64, payer *Account, ontId string, attributes []*DDOAttribute, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

attributes: attributes of ONT ID

index: key index of ONT ID

signer: signer account

2.5.20 Remove Attribute

ontSdk.Native.OntId.RemoveAttribute(gasPrice, gasLimit uint64, payer *Account, ontId string, removeKey []byte, signer *Account) (common.Uint256, error)

ontId: ONT ID

removeKey: key of attribute want to remove

signer: public key of ONT ID and signer account

2.5.21 Remove Attribute By Index

ontSdk.Native.OntId.RemoveAttributeByIndex(gasPrice, gasLimit uint64, payer *Account, ontId, removeKey []byte, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

removeKey: key of attribute want to remove

index: key index of ONT ID

signer: signer account

2.5.22 Add Attributes By Controller

ontSdk.Native.OntId.AddAttributesByController(gasPrice, gasLimit uint64, payer *Account, ontId string, attributes []*DDOAttribute, signers []ontid.Signer, controllerSigners []*Account) (common.Uint256, error)

ontId: ONT ID

attributes: attributes of ONT ID

signers: signer ONT IDs and its key index

controllerSigners: signer accounts

2.5.23 Remove Attributes By Controller

ontSdk.Native.OntId.RemoveAttributesByController(gasPrice, gasLimit uint64, payer *Account, ontId string, key []byte, signers []ontid.Signer, controllerSigners []*Account) (common.Uint256, error)

ontId: ONT ID

key: key of attribute want to remove

signers: signer ONT IDs and its key index

controllerSigners: signer accounts

2.5.24 Add New AuthKey

ontSdk.Native.OntId.AddNewAuthKey(gasPrice, gasLimit uint64, payer *Account, ontId string, publicKey []byte, controller string, signIndex uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

publicKey: public key of ONT ID

controller: controller ONT ID of this public key

signIndex: key index of ONT ID

signer: signer account

2.5.25 Add NewAuth Key By Recovery

ontSdk.Native.OntId.AddNewAuthKeyByRecovery(gasPrice, gasLimit uint64, payer *Account, ontId string, publicKey []byte, controller string, signers []ontid.Signer, recoverySigners []*Account) (common.Uint256, error)

ontId: ONT ID

publicKey: public key of ONT ID

controller: controller ONT ID of this public key

signers: signer ONT IDs and its key index

recoverySigners: signer accounts

2.5.26 Add New AuthKey By Controller

ontSdk.Native.OntId.AddNewAuthKeyByController(gasPrice, gasLimit uint64, payer *Account, ontId string, publicKey []byte, controller string, signers []ontid.Signer, controllerSigners []*Account) (common.Uint256, error)

ontId: ONT ID

publicKey: public key of ONT ID

controller: controller ONT ID of this public key

signers: signer ONT IDs and its key index

controllerSigners: signer accounts

2.5.27 Set AuthKey

ontSdk.Native.OntId.SetAuthKey(gasPrice, gasLimit uint64, payer *Account, ontId string, index, signIndex uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

index: key index of public key want to set to auth

signIndex: key index of ONT ID of signer

signer: signer account

2.5.28 Set AuthKey By Recovery

ontSdk.Native.OntId.SetAuthKeyByRecovery(gasPrice, gasLimit uint64, payer *Account, ontId string, index uint32, signers []ontid.Signer, recoverySigners []*Account) (common.Uint256, error)

ontId: ONT ID

index: key index of public key want to set to auth

signers: signer ONT IDs and its key index

recoverySigners: signer accounts

2.5.29 Set AuthKey By Controller

ontSdk.Native.OntId.SetAuthKeyByController(gasPrice, gasLimit uint64, payer *Account, ontId string, index uint32, signers []ontid.Signer, controllerSigners []*Account) (common.Uint256, error)

ontId: ONT ID

index: key index of public key want to set to auth

signers: signer ONT IDs and its key index

controllerSigners: signer accounts

2.5.30 Remove AuthKey

ontSdk.Native.OntId.RemoveAuthKey(gasPrice, gasLimit uint64, payer *Account, ontId string, index uint32, signIndex uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

index: key index of public key want to remove from auth

signIndex: key index of ONT ID of signer

signer: signer account

2.5.31 Remove AuthKey By Recovery

ontSdk.Native.OntId.RemoveAuthKeyByRecovery(gasPrice, gasLimit uint64, payer *Account, ontId string, index uint32, signers []ontid.Signer, recoverySigners []*Account) (common.Uint256, error)

ontId: ONT ID

index: key index of public key want to remove from auth

signers: signer ONT IDs and its key index

recoverySigners: signer accounts

2.5.32 Remove AuthKey By Controller

ontSdk.Native.OntId.RemoveAuthKeyByController(gasPrice, gasLimit uint64, payer *Account, ontId string, index uint32, signers []ontid.Signer, controllerSigners []*Account) (common.Uint256, error)

ontId: ONT ID

index: key index of public key want to remove from auth

signers: signer ONT IDs and its key index

controllerSigners: signer accounts

2.5.33 Add Service

ontSdk.Native.OntId.AddService(gasPrice, gasLimit uint64, payer *Account, ontId string, serviceId, type_, serviceEndpint []byte, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

serviceId: service Id

type_: service type

serviceEndpint: service endpint

index: key index of ONT ID

signer: signer account

2.5.34 Update Service

ontSdk.Native.OntId.UpdateService(gasPrice, gasLimit uint64, payer *Account, ontId string, serviceId, type_, serviceEndpint []byte, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

serviceId: service Id

type_: service type

serviceEndpint: service endpint

index: key index of ONT ID

signer: signer account

2.5.35 Remove Service

ontSdk.Native.OntId.RemoveService(gasPrice, gasLimit uint64, payer *Account, ontId string, serviceId []byte, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

serviceId: service Id want to remove

index: key index of ONT ID

signer: signer account

2.5.36 Add Context

ontSdk.Native.OntId.AddContext(gasPrice, gasLimit uint64, payer *Account, ontId string, contexts [][]byte, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

contexts: contexts want to add

index: key index of ONT ID

signer: signer account

2.5.37 Remove Context

ontSdk.Native.OntId.RemoveContext(gasPrice, gasLimit uint64, payer *Account, ontId string, contexts [][]byte, index uint32, signer *Account) (common.Uint256, error)

ontId: ONT ID

contexts: contexts want to remove

index: key index of ONT ID

signer: signer account

2.5.38 Verify Signature

ontSdk.Native.OntId.VerifySignature(ontId string, keyIndex uint64, account *Account) (bool, error)

ontId: ONT ID

keyIndex: key index of ONT ID

account: signer account

2.5.39 Verify Controller

ontSdk.Native.OntId.VerifyController(ontId string, signers []ontid.Signer, accounts []*Account) (bool, error)

ontId: ONT ID

signers: signer ONT IDs and its key index

accounts: signer accounts

2.5.40 Get PublicKeys Json

ontSdk.Native.OntId.GetPublicKeysJson(ontId string) ([]byte, error)

ontId: ONT ID

2.5.41 Get Attributes Json

ontSdk.Native.OntId.GetAttributesJson(ontId string) ([]byte, error)

ontId: ONT ID

2.5.42 Get Attributes

ontSdk.Native.OntId.GetAttributes(ontId string) ([]byte, error)

ontId: ONT ID

2.5.43 Get Attribute ByKey

ontSdk.Native.OntId.GetAttributeByKey(ontId, key string) ([]byte, error)

ontId: ONT ID

key: key of attribute want to query

2.5.44 Get Service Json

ontSdk.Native.OntId.GetServiceJson(ontId string, serviceId string) ([]byte, error)

ontId: ONT ID

serviceId: service Id want to query

2.5.45 Get KeyState

ontSdk.Native.OntId.GetKeyState(ontId string, keyIndex int) (string, error)

ontId: ONT ID

keyIndex: key index of ONT ID

2.5.46 Get Controller Json

ontSdk.Native.OntId.GetControllerJson(ontId string) ([]byte, error)

ontId: ONT ID

2.5.47 Get Document Json

ontSdk.Native.OntId.GetDocumentJson(ontId string) ([]byte, error)

ontId: ONT ID

2.6 Credential API

2.6.1 Gen Sign Req

ontSdk.Credential.GenSignReq(credentialSubject interface{}, ontId string, signer *Account) (*Request, error)

credentialSubject: credentialSubject of Credential

ontId: holder ONT ID

signer: signer account

2.6.2 Verify Sign Req

ontSdk.Credential.VerifySignReq(request *Request) error

request: result of GenSignReq

2.6.3 Create Credential

ontSdk.Credential.CreateCredential(contexts []string, types []string, credentialSubject interface{}, issuerId string, expirationDateTimestamp int64, signer *Account) (*VerifiableCredential, uint32, error)

contexts: definition

types: definition

credentialSubject: credentialSubject of Credential

issuerId: ONT ID of issuer

expirationDateTimestamp: unix of expiration date timestamp

signer: signer account

2.6.4 Commit Credential

ontSdk.Credential.CommitCredential(gasPrice, gasLimit uint64, credentialId, issuerId, holderId string, index uint32, signer, payer *Account) (common.Uint256, error)

credentialId: Id of credential

issuerId: ONT ID of issuer

holderId: ONT ID of holder

index: key index of issuer used to sign tx

signer: signer account

2.6.5 Verify Credible OntId

ontSdk.Credential.VerifyCredibleOntId(credibleOntIds []string, credential *VerifiableCredential) error

credibleOntIds: credible ONT ID list

credential: definition

2.6.6 Verify Not Expired

ontSdk.Credential.VerifyNotExpired(credential *VerifiableCredential) error

credential: definition

2.6.7 Verify Issuer Signature

ontSdk.Credential.VerifyIssuerSignature(credential *VerifiableCredential) error

credential: definition

2.6.8 Verify Status

ontSdk.Credential.VerifyStatus(credential *VerifiableCredential) error

credential: definition

2.6.9 Create Presentation

ontSdk.Credential.CreatePresentation(credentials []*VerifiableCredential, contexts, types []string, holder string, signers []*Account) (*Presentation, error)

credentials: credential list

contexts: definition

types: definition

holder: ONTID of holder

signers: signer accounts

2.6.10 Verify Presentation

ontSdk.Credential.VerifyPresentation(presentation *Presentation, credibleOntIds []string) error

presentation: definition

credibleOntIds: credible ONT ID list

Contributing

Can I contribute patches to the Ontology project?

Yes! We appreciate your help!

Please open a pull request with signed-off commits. This means adding a line that says "Signed-off-by: Name " at the end of each commit, indicating that you wrote the code and have the right to pass it on as an open source patch. If you don't sign off your patches, we will not accept them.

You can also send your patches as emails to the developer mailing list. Please join the Ontology mailing list or forum and talk to us about it.

Also, please write good git commit messages. A good commit message looks like this:

Header line: explain the commit in one line

The body of the commit message should be a few lines of text, explaining things in more detail, possibly giving some background about the issue being fixed, etc.

The body of the commit message can be several paragraphs long, and should use proper word-wrapping and keep the columns shorter than about 74 characters or so. That way "git log" will show things nicely even when it's indented.

Make sure you explain your solution and why you're doing what you're doing, and not just what you're doing. Reviewers (and your future self) can read the patch, but might not understand why a particular solution was implemented.

Reported-by: whoever-reported-it Signed-off-by: Your Name [email protected]

Website

License

The Ontology library (i.e. all of the code outside of the cmd directory) is licensed under the GNU Lesser General Public License v3.0, also included in our repository in the License file.

ontology-go-sdk's People

Contributors

alverlyu avatar arbio5zt avatar blockchain-develop avatar chenzhijie avatar honglei-cong avatar jasonzhoupw avatar laizy avatar lucas7788 avatar qiluge avatar rain-zxn avatar rongyi avatar sheldonzhao avatar siovanus avatar skyinglyh1 avatar tanziwen avatar voodoo12345 avatar xiemylogos avatar yihen-liu avatar zjhmale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ontology-go-sdk's Issues

Build error

This is my test code

package main

import (
	"fmt"
	sdk "github.com/ontio/ontology-go-sdk"
)

func main() {
	sdkClient := sdk.NewOntologySdk()
	sdkClient.NewRpcClient().SetAddress("http://dappnode1.ont.io:20336")
	height, err := sdkClient.GetCurrentBlockHeight()
	if err != nil {
		fmt.Printf("get current block height failed, err: %s\n", err.Error())
		return
	}
	fmt.Printf("current block height is %d\n", height)
}

It returns some error info where I try to build the project.

# ontSdk
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: warning: ignoring file /Users/lilin/go/pkg/mod/github.com/ontio/[email protected]/smartcontract/service/wasmvm/libwasmjit_onto_interface_darwin.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
  "_wasmjit_bytes_destroy", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_bytes_destroy in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_bytes_destroy)
  "_wasmjit_chain_context_create", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_chain_context_create in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_chain_context_create)
  "_wasmjit_construct_result", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_construct_result in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_construct_result)
  "_wasmjit_get_exec_step", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_get_exec_step in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_get_exec_step)
  "_wasmjit_get_gas", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_get_gas in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_get_gas)
  "_wasmjit_invoke", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_invoke in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_invoke)
  "_wasmjit_service_index", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_service_index in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_service_index)
  "_wasmjit_set_calloutput", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_set_calloutput in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_set_calloutput)
  "_wasmjit_set_exec_step", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_set_exec_step in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_set_exec_step)
  "_wasmjit_set_gas", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_set_gas in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_set_gas)
  "_wasmjit_validate", referenced from:
      __cgo_d02b16eeae27_Cfunc_wasmjit_validate in 000019.o
     (maybe you meant: __cgo_d02b16eeae27_Cfunc_wasmjit_validate)
ld: symbol(s) not found for architecture arm64
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

Add documentation on how to install project from source and run test cases

I am not able to install correctly the project and run the test cases. I did as follow:

  1. glide update
  2. go test ./..

and got the following error message:

--- FAIL: TestOntId_RegIDWithPublicKey (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x8ff719]

goroutine 5 [running]:
testing.tRunner.func1(0xc0000e0300)
	/usr/local/go/src/testing/testing.go:830 +0x388
panic(0x98b2a0, 0xf06250)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/ontio/ontology-go-sdk.(*Wallet).NewIdentity(0x0, 0x10212, 0xece31c, 0x6, 0x6, 0xc0000b0d10, 0x4ecefd, 0xc05df0)
	/home/dau/workspace/go/src/github.com/ontio/ontology-go-sdk/wallet.go:450 +0x29
github.com/ontio/ontology-go-sdk.(*Wallet).NewDefaultSettingIdentity(...)
	/home/dau/workspace/go/src/github.com/ontio/ontology-go-sdk/wallet.go:472
github.com/ontio/ontology-go-sdk.TestOntId_RegIDWithPublicKey(0xc0000e0300)
	/home/dau/workspace/go/src/github.com/ontio/ontology-go-sdk/native_contract_test.go:12 +0x70
testing.tRunner(0xc0000e0300, 0xa5f0d0)
	/usr/local/go/src/testing/testing.go:865 +0xc0
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:916 +0x357
FAIL	github.com/ontio/ontology-go-sdk	0.008s
?   	github.com/ontio/ontology-go-sdk/bip44	[no test files]
?   	github.com/ontio/ontology-go-sdk/client	[no test files]
?   	github.com/ontio/ontology-go-sdk/common	[no test files]
--- FAIL: TestOep4 (0.85s)
    oep4_test.go:59: open ../../wallet.json: no such file or directory
FAIL
FAIL	github.com/ontio/ontology-go-sdk/oep4	0.855s
?   	github.com/ontio/ontology-go-sdk/test	[no test files]
?   	github.com/ontio/ontology-go-sdk/utils	[no test files]

Update to Contributing Guidelines

Currently, the guidelines say to have commit messages be numerous sections and potentially paragraphs. I think it would be better practice to follow the 50/72 formatting:

For these reasons, the "summary" must be no more than 70-75
characters, and it must describe both what the patch changes, as well
as why the patch might be necessary. It is challenging to be both
succinct and descriptive, but that is what a well-written summary
should do.

The commit message for my PR is 101 characters and GitHub even cuts it off at 70 characters. I think it would be better to change the guidelines so that the pull requests answer certain questions (like what they are fixing, why, etc).

It should also be noted that the people should be using git commit --signoff.

oep4 parseOep4TransferEvent address error?

Hi, I use FetchTxTransferEvent to get oep4 token tx, but find 'from' and 'to' address is not correct. then i debug and find parseOep4TransferEvent parse address has some problem, the hex string is reversed. can somebody make sure this?

gosdk 的 ont|ong.transfer 怎么设置 payer?

假设: a 向 b 转账 1 ONT,通常是a地址扣除1ONT,0.01ONG, b地址收到1ONT
看见java sdk中可以设置 gas 的扣费地址,是不是说 可以设置为 0.01ONG由 C 地址扣除

gosdk中, MutableTransaction 也可以设置Payer

type MutableTransaction struct {
	Version  byte
	TxType   TransactionType
	Nonce    uint32
	GasPrice uint64
	GasLimit uint64
	Payer    common.Address
	Payload  Payload
	//Attributes []*TxAttribute
	attributes byte //this must be 0 now, Attribute Array length use VarUint encoding, so byte is enough for extension
	Sigs       []Sig
}

那么怎么构造这样的交易呢?

upgrade dependence iavl

released version higher than v1.12 require package github.com/tendermint/[email protected], 1.14.0 require pakage github.com/tendermint/tendermint v0.33.5,
pakage [email protected] is too old ,iavl version now is up to 1.17.x, and require tendermint up to v0.35.2 , expect upgrade dependence iavl cause other projects can not downgrade tendermint version to v0.33.5

Build error

When use ontology-go-sdk, errors below are reported, we need to delete vendor/github.com/ontio/ontology/vendor/github.com/ontio/ontology-crypto to build successfully.

vendor/github.com/ontio/ontology-go-sdk/common/common.go:71:10: cannot use []"company/project/repo/vendor/github.com/ontio/ontology-crypto/keypair".PublicKey literal (type []"company/project/repo/vendor/github.com/ontio/ontology-crypto/keypair".PublicKey) as type []"company/project/repo/vendor/github.com/ontio/ontology/vendor/github.com/ontio/ontology-crypto/keypair".PublicKey in field value
vendor/github.com/ontio/ontology-go-sdk/common/common.go:97:46: cannot use pubKeys (type []"company/project/repo/vendor/github.com/ontio/ontology-crypto/keypair".PublicKey) as type []"company/project/repo/vendor/github.com/ontio/ontology/vendor/github.com/ontio/ontology-crypto/keypair".PublicKey in argument to types.AddressFromMultiPubKeys
vendor/github.com/ontio/ontology-go-sdk/common/common.go:113:23: cannot use sigs.PubKeys (type []"company/project/repo/vendor/github.com/ontio/ontology/vendor/github.com/ontio/ontology-crypto/keypair".PublicKey) as type []"company/project/repo/vendor/github.com/ontio/ontology-crypto/keypair".PublicKey in argument to pubKeysEqual
vendor/github.com/ontio/ontology-go-sdk/common/common.go:125:11: cannot use pubKeys (type []"company/project/repo/vendor/github.com/ontio/ontology-crypto/keypair".PublicKey) as type []"company/project/repo/vendor/github.com/ontio/ontology/vendor/github.com/ontio/ontology-crypto/keypair".PublicKey in field value
vendor/github.com/ontio/ontology-go-sdk/common/common.go:171:27: cannot use signer.SigScheme (type "company/project/repo/vendor/github.com/ontio/ontology/vendor/github.com/ontio/ontology-crypto/signature".SignatureScheme) as type "company/project/repo/vendor/github.com/ontio/ontology-crypto/signature".SignatureScheme in argument to "company/project/repo/vendor/github.com/ontio/ontology-crypto/signature".Sign

go sdk

when use ontology-go-sdk package

rpc.go:37:2: cannot find package "github.com/ontio/ontology/smartcontract/service/wasm" in any of:
/usr/lib/golang/src/github.com/ontio/ontology/smartcontract/service/wasm (from $GOROOT)
/root/gocode/src/github.com/ontio/ontology/smartcontract/service/wasm (from $GOPATH)
../utils/utils.go:28:2: cannot find package "github.com/ontio/ontology/vm/types" in any of:
/usr/lib/golang/src/github.com/ontio/ontology/vm/types (from $GOROOT)
/root/gocode/src/github.com/ontio/ontology/vm/types (from $GOPATH)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.