dna_go_sdk

package module
v0.0.0-...-2db5e21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2019 License: Apache-2.0 Imports: 29 Imported by: 6

README

Go SDK For DNA

1. Overview

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

2. How to use?

First, create an DNASDK instance with the NewDNASdk method.

ontSdk := NewDNASdk()

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 DNA
ontSdk.GetVersion() (string, error)
2.1.17 Get network id of DNA
ontSdk.GetNetworkId() (uint32, error)
2.1.18 Send transaction to DNA
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)

DNA 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.

DNA 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.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)

Contributing

Can I contribute patches to the DNA 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 DNA 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 youremail@yourhost.com

Website

License

The DNA 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.

Documentation

Overview

Ontolog sdk in golang. Using for operation with dna

Index

Constants

View Source
const (
	SCHEME = "did"
	METHOD = "ont"
	VER    = 0x41
)
View Source
const (
	KEY_STATUS_REVOKE = "revoked"
	KEY_STSTUS_IN_USE = "in use"
)

Variables

View Source
var (
	ONT_CONTRACT_ADDRESS, _           = utils.AddressFromHexString("0100000000000000000000000000000000000000")
	ONG_CONTRACT_ADDRESS, _           = utils.AddressFromHexString("0200000000000000000000000000000000000000")
	ONT_ID_CONTRACT_ADDRESS, _        = utils.AddressFromHexString("0300000000000000000000000000000000000000")
	GLOABL_PARAMS_CONTRACT_ADDRESS, _ = utils.AddressFromHexString("0400000000000000000000000000000000000000")
	AUTH_CONTRACT_ADDRESS, _          = utils.AddressFromHexString("0600000000000000000000000000000000000000")
	GOVERNANCE_CONTRACT_ADDRESS, _    = utils.AddressFromHexString("0700000000000000000000000000000000000000")
)
View Source
var (
	ONT_CONTRACT_VERSION           = byte(0)
	ONG_CONTRACT_VERSION           = byte(0)
	ONT_ID_CONTRACT_VERSION        = byte(0)
	GLOBAL_PARAMS_CONTRACT_VERSION = byte(0)
	AUTH_CONTRACT_VERSION          = byte(0)
	GOVERNANCE_CONTRACT_VERSION    = byte(0)
)
View Source
var DEFAULT_WALLET_NAME = "MyWallet"
View Source
var DEFAULT_WALLET_VERSION = "1.1"
View Source
var ERR_ACCOUNT_NOT_FOUND = errors.New("account not found")
View Source
var ERR_CONTROLLER_NOT_FOUND = errors.New("controller not found")
View Source
var ERR_IDENTITY_NOT_FOUND = errors.New("identity not found")

Functions

func CheckKeyTypeCurve

func CheckKeyTypeCurve(keyType keypair.KeyType, curveCode byte) bool

func CheckSigScheme

func CheckSigScheme(keyType keypair.KeyType, sigScheme s.SignatureScheme) bool

func CreateID

func CreateID(nonce []byte) (string, error)

func GenerateID

func GenerateID() (string, error)

func GetCurveName

func GetCurveName(pubKey []byte) string

func GetKeyTypeString

func GetKeyTypeString(keyType keypair.KeyType) string

func ScryptEqual

func ScryptEqual(s1, s2 *keypair.ScryptParam) bool

func VerifyID

func VerifyID(id string) bool

Types

type Account

type Account struct {
	PrivateKey keypair.PrivateKey
	PublicKey  keypair.PublicKey
	Address    common.Address
	SigScheme  s.SignatureScheme
}

crypto object

func NewAccount

func NewAccount(sigscheme ...s.SignatureScheme) *Account

func (*Account) GetPrivateKey

func (this *Account) GetPrivateKey() keypair.PrivateKey

func (*Account) GetPublicKey

func (this *Account) GetPublicKey() keypair.PublicKey

func (*Account) GetSigScheme

func (this *Account) GetSigScheme() s.SignatureScheme

func (*Account) Sign

func (this *Account) Sign(data []byte) ([]byte, error)

type AccountData

type AccountData struct {
	keypair.ProtectedKey

	Label     string `json:"label"`
	PubKey    string `json:"publicKey"`
	SigSch    string `json:"signatureScheme"`
	IsDefault bool   `json:"isDefault"`
	Lock      bool   `json:"lock"`
	// contains filtered or unexported fields
}

* AccountData - for wallet read and save, no crypto object included *

func NewAccountData

func NewAccountData(keyType keypair.KeyType, curveCode byte, sigScheme s.SignatureScheme, passwd []byte, scrypts ...*keypair.ScryptParam) (*AccountData, error)

func (*AccountData) Clone

func (this *AccountData) Clone() *AccountData

func (*AccountData) GetAccount

func (this *AccountData) GetAccount(passwd []byte) (*Account, error)

func (*AccountData) GetKeyPair

func (this *AccountData) GetKeyPair() *keypair.ProtectedKey

func (*AccountData) GetScrypt

func (this *AccountData) GetScrypt() *keypair.ScryptParam

func (*AccountData) SetKeyPair

func (this *AccountData) SetKeyPair(keyinfo *keypair.ProtectedKey)

func (*AccountData) SetScript

func (this *AccountData) SetScript(scrypt *keypair.ScryptParam)

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

func (*Auth) AssignFuncsToRole

func (this *Auth) AssignFuncsToRole(gasPrice, gasLimit uint64, contractAddress common.Address, signer *Account, adminId, role []byte, funcNames []string, keyIndex int) (common.Uint256, error)

func (*Auth) AssignOntIDsToRole

func (this *Auth) AssignOntIDsToRole(gasPrice, gasLimit uint64, signer *Account, contractAddress common.Address, admontId, role []byte, persons [][]byte, keyIndex int) (common.Uint256, error)

func (*Auth) Delegate

func (this *Auth) Delegate(gasPrice, gasLimit uint64, signer *Account, contractAddress common.Address, from, to, role []byte, period, level, keyIndex int) (common.Uint256, error)

func (*Auth) NewAssignFuncsToRoleTransaction

func (this *Auth) NewAssignFuncsToRoleTransaction(gasPrice, gasLimit uint64, contractAddress common.Address, adminId, role []byte, funcNames []string, keyIndex int) (*types.MutableTransaction, error)

func (*Auth) NewAssignOntIDsToRoleTransaction

func (this *Auth) NewAssignOntIDsToRoleTransaction(gasPrice, gasLimit uint64, contractAddress common.Address, admontId, role []byte, persons [][]byte, keyIndex int) (*types.MutableTransaction, error)

func (*Auth) NewDelegateTransaction

func (this *Auth) NewDelegateTransaction(gasPrice, gasLimit uint64, contractAddress common.Address, from, to, role []byte, period, level, keyIndex int) (*types.MutableTransaction, error)

func (*Auth) NewTransferTransaction

func (this *Auth) NewTransferTransaction(gasPrice, gasLimit uint64, contractAddress common.Address, newAdminId []byte, keyIndex int) (*types.MutableTransaction, error)

func (*Auth) NewVerifyTokenTransaction

func (this *Auth) NewVerifyTokenTransaction(gasPrice, gasLimit uint64, contractAddress common.Address, caller []byte, funcName string, keyIndex int) (*types.MutableTransaction, error)

func (*Auth) NewWithdrawTransaction

func (this *Auth) NewWithdrawTransaction(gasPrice, gasLimit uint64, contractAddress common.Address, initiator, delegate, role []byte, keyIndex int) (*types.MutableTransaction, error)

func (*Auth) Transfer

func (this *Auth) Transfer(gasPrice, gasLimit uint64, signer *Account, contractAddress common.Address, newAdminId []byte, keyIndex int) (common.Uint256, error)

func (*Auth) VerifyToken

func (this *Auth) VerifyToken(gasPrice, gasLimit uint64, signer *Account, contractAddress common.Address, caller []byte, funcName string, keyIndex int) (common.Uint256, error)

func (*Auth) Withdraw

func (this *Auth) Withdraw(gasPrice, gasLimit uint64, signer *Account, contractAddress common.Address, initiator, delegate, role []byte, keyIndex int) (common.Uint256, error)

type Controller

type Controller struct {
	ID         string
	PrivateKey keypair.PrivateKey
	PublicKey  keypair.PublicKey
	SigScheme  s.SignatureScheme
}

func (*Controller) GetPrivateKey

func (this *Controller) GetPrivateKey() keypair.PrivateKey

func (*Controller) GetPublicKey

func (this *Controller) GetPublicKey() keypair.PublicKey

func (*Controller) GetSigScheme

func (this *Controller) GetSigScheme() s.SignatureScheme

func (*Controller) Sign

func (this *Controller) Sign(data []byte) ([]byte, error)

type ControllerData

type ControllerData struct {
	ID     string `json:"id"`
	Public string `json:"publicKey,omitemtpy"`
	SigSch string `json:"signatureScheme"`
	keypair.ProtectedKey
	// contains filtered or unexported fields
}

func NewControllerData

func NewControllerData(id string, keyType keypair.KeyType, curveCode byte, sigScheme s.SignatureScheme, passwd []byte, scrypts ...*keypair.ScryptParam) (*ControllerData, error)

func NewControllerDataFromProtectedKey

func NewControllerDataFromProtectedKey(id, pubKey string, protectedKey *keypair.ProtectedKey, SigSch string, scrypts ...*keypair.ScryptParam) *ControllerData

func (*ControllerData) Clone

func (this *ControllerData) Clone() *ControllerData

func (*ControllerData) GetController

func (this *ControllerData) GetController(passwd []byte) (*Controller, error)

func (*ControllerData) GetKeyPair

func (this *ControllerData) GetKeyPair() *keypair.ProtectedKey

func (*ControllerData) GetScrypt

func (this *ControllerData) GetScrypt() *keypair.ScryptParam

func (*ControllerData) SetKeyPair

func (this *ControllerData) SetKeyPair(keyinfo *keypair.ProtectedKey)

type DDO

type DDO struct {
	OntId      string
	Owners     []*DDOOwner
	Attributes []*DDOAttribute
	Recovery   string
}

type DDOAttribute

type DDOAttribute struct {
	Key       []byte
	ValueType []byte
	Value     []byte
}

type DDOOwner

type DDOOwner struct {
	PubKeyId string
	Type     string
	Curve    string
	Value    string
	// contains filtered or unexported fields
}

func (*DDOOwner) GetIndex

func (this *DDOOwner) GetIndex() uint32

type DNASdk

type DNASdk struct {
	client.ClientMgr
	Native *NativeContract
	NeoVM  *NeoVMContract
}

DNASdk is the main struct for user

func NewDNASdk

func NewDNASdk() *DNASdk

NewDNASdk return DNASdk.

func (*DNASdk) CreateWallet

func (this *DNASdk) CreateWallet(walletFile string) (*Wallet, error)

CreateWallet return a new wallet

func (*DNASdk) GetAdddrByPubKey

func (this *DNASdk) GetAdddrByPubKey(pubKey keypair.PublicKey) string

func (*DNASdk) GetMultiAddr

func (this *DNASdk) GetMultiAddr(pubkeys []keypair.PublicKey, m int) (string, error)

func (*DNASdk) GetMutableTx

func (this *DNASdk) GetMutableTx(rawTx string) (*types.MutableTransaction, error)

func (*DNASdk) GetTxData

func (this *DNASdk) GetTxData(tx *types.MutableTransaction) (string, error)

func (*DNASdk) MultiSignToTransaction

func (this *DNASdk) MultiSignToTransaction(tx *types.MutableTransaction, m uint16, pubKeys []keypair.PublicKey, signer Signer) error

func (*DNASdk) NewInvokeTransaction

func (this *DNASdk) NewInvokeTransaction(gasPrice, gasLimit uint64, invokeCode []byte) *types.MutableTransaction

NewInvokeTransaction return smart contract invoke transaction

func (*DNASdk) OpenWallet

func (this *DNASdk) OpenWallet(walletFile string) (*Wallet, error)

OpenWallet return a wallet instance

func (*DNASdk) SignToTransaction

func (this *DNASdk) SignToTransaction(tx *types.MutableTransaction, signer Signer) error

type GlobalParam

type GlobalParam struct {
	// contains filtered or unexported fields
}

func (*GlobalParam) AcceptAdmin

func (this *GlobalParam) AcceptAdmin(gasPrice, gasLimit uint64, signer *Account) (common.Uint256, error)

func (*GlobalParam) CreateSnapshot

func (this *GlobalParam) CreateSnapshot(gasPrice, gasLimit uint64, signer *Account) (common.Uint256, error)

func (*GlobalParam) GetGlobalParams

func (this *GlobalParam) GetGlobalParams(params []string) (map[string]string, error)

func (*GlobalParam) NewAcceptAdminTransaction

func (this *GlobalParam) NewAcceptAdminTransaction(gasPrice, gasLimit uint64, admin common.Address) (*types.MutableTransaction, error)

func (*GlobalParam) NewCreateSnapshotTransaction

func (this *GlobalParam) NewCreateSnapshotTransaction(gasPrice, gasLimit uint64) (*types.MutableTransaction, error)

func (*GlobalParam) NewSetGlobalParamsTransaction

func (this *GlobalParam) NewSetGlobalParamsTransaction(gasPrice, gasLimit uint64, params map[string]string) (*types.MutableTransaction, error)

func (*GlobalParam) NewSetOperatorTransaction

func (this *GlobalParam) NewSetOperatorTransaction(gasPrice, gasLimit uint64, operator common.Address) (*types.MutableTransaction, error)

func (*GlobalParam) NewTransferAdminTransaction

func (this *GlobalParam) NewTransferAdminTransaction(gasPrice, gasLimit uint64, newAdmin common.Address) (*types.MutableTransaction, error)

func (*GlobalParam) SetGlobalParams

func (this *GlobalParam) SetGlobalParams(gasPrice, gasLimit uint64, signer *Account, params map[string]string) (common.Uint256, error)

func (*GlobalParam) SetOperator

func (this *GlobalParam) SetOperator(gasPrice, gasLimit uint64, signer *Account, operator common.Address) (common.Uint256, error)

func (*GlobalParam) TransferAdmin

func (this *GlobalParam) TransferAdmin(gasPrice, gasLimit uint64, signer *Account, newAdmin common.Address) (common.Uint256, error)

type Identity

type Identity struct {
	ID        string
	Label     string
	Lock      bool
	IsDefault bool

	Extra interface{}
	// contains filtered or unexported fields
}

func NewIdentity

func NewIdentity(scrypt *keypair.ScryptParam) (*Identity, error)

func NewIdentityFromIdentityData

func NewIdentityFromIdentityData(identityData *IdentityData) (*Identity, error)

func (*Identity) AddControllerData

func (this *Identity) AddControllerData(controllerData *ControllerData) error

func (*Identity) ControllerCount

func (this *Identity) ControllerCount() int

func (*Identity) DeleteControllerData

func (this *Identity) DeleteControllerData(id string) error

func (*Identity) GetControllerById

func (this *Identity) GetControllerById(id string, passwd []byte) (*Controller, error)

func (*Identity) GetControllerByIndex

func (this *Identity) GetControllerByIndex(index int, passwd []byte) (*Controller, error)

func (*Identity) GetControllerByPubKey

func (this *Identity) GetControllerByPubKey(pubKey string, passwd []byte) (*Controller, error)

func (*Identity) GetControllerDataById

func (this *Identity) GetControllerDataById(id string) (*ControllerData, error)

func (*Identity) GetControllerDataByIndex

func (this *Identity) GetControllerDataByIndex(index int) (*ControllerData, error)

func (*Identity) GetControllerDataByPubKey

func (this *Identity) GetControllerDataByPubKey(pubKey string) (*ControllerData, error)

func (*Identity) NewController

func (this *Identity) NewController(id string, keyType keypair.KeyType, curveCode byte, sigScheme s.SignatureScheme, passwd []byte) (*Controller, error)

func (*Identity) NewDefaultSettingController

func (this *Identity) NewDefaultSettingController(id string, passwd []byte) (*Controller, error)

func (*Identity) ToIdentityData

func (this *Identity) ToIdentityData() *IdentityData

type IdentityData

type IdentityData struct {
	ID        string            `json:"ontid"`
	Label     string            `json:"label,omitempty"`
	Lock      bool              `json:"lock"`
	IsDefault bool              `json:"isDefault"`
	Control   []*ControllerData `json:"controls,omitempty"`
	Extra     interface{}       `json:"extra,omitempty"`
	// contains filtered or unexported fields
}

type NativeContract

type NativeContract struct {
	Ont          *Ont
	Ong          *Ong
	OntId        *OntId
	GlobalParams *GlobalParam
	Auth         *Auth
	// contains filtered or unexported fields
}

func (*NativeContract) InvokeNativeContract

func (this *NativeContract) InvokeNativeContract(
	gasPrice,
	gasLimit uint64,
	singer *Account,
	version byte,
	contractAddress common.Address,
	method string,
	params []interface{},
) (common.Uint256, error)

func (*NativeContract) NewNativeInvokeTransaction

func (this *NativeContract) NewNativeInvokeTransaction(
	gasPrice,
	gasLimit uint64,
	version byte,
	contractAddress common.Address,
	method string,
	params []interface{},
) (*types.MutableTransaction, error)

func (*NativeContract) PreExecInvokeNativeContract

func (this *NativeContract) PreExecInvokeNativeContract(
	contractAddress common.Address,
	version byte,
	method string,
	params []interface{},
) (*sdkcom.PreExecResult, error)

type NeoVMContract

type NeoVMContract struct {
	// contains filtered or unexported fields
}

func (*NeoVMContract) DeployNeoVMSmartContract

func (this *NeoVMContract) DeployNeoVMSmartContract(
	gasPrice,
	gasLimit uint64,
	singer *Account,
	needStorage bool,
	code,
	name,
	version,
	author,
	email,
	desc string) (common.Uint256, error)

DeploySmartContract Deploy smart contract to dna

func (*NeoVMContract) InvokeNeoVMContract

func (this *NeoVMContract) InvokeNeoVMContract(
	gasPrice,
	gasLimit uint64,
	signer *Account,
	contractAddress common.Address,
	params []interface{}) (common.Uint256, error)

func (*NeoVMContract) NewDeployNeoVMCodeTransaction

func (this *NeoVMContract) NewDeployNeoVMCodeTransaction(gasPrice, gasLimit uint64, contract *sdkcom.SmartContract) *types.MutableTransaction

func (*NeoVMContract) NewNeoVMInvokeTransaction

func (this *NeoVMContract) NewNeoVMInvokeTransaction(
	gasPrice,
	gasLimit uint64,
	contractAddress common.Address,
	params []interface{},
) (*types.MutableTransaction, error)

func (*NeoVMContract) PreExecInvokeNeoVMContract

func (this *NeoVMContract) PreExecInvokeNeoVMContract(
	contractAddress common.Address,
	params []interface{}) (*sdkcom.PreExecResult, error)

type Ong

type Ong struct {
	// contains filtered or unexported fields
}

func (*Ong) Allowance

func (this *Ong) Allowance(from, to common.Address) (uint64, error)

func (*Ong) Approve

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

func (*Ong) BalanceOf

func (this *Ong) BalanceOf(address common.Address) (uint64, error)

func (*Ong) Decimals

func (this *Ong) Decimals() (byte, error)

func (*Ong) MultiTransfer

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

func (*Ong) Name

func (this *Ong) Name() (string, error)

func (*Ong) NewApproveTransaction

func (this *Ong) NewApproveTransaction(gasPrice, gasLimit uint64, from, to common.Address, amount uint64) (*types.MutableTransaction, error)

func (*Ong) NewMultiTransferTransaction

func (this *Ong) NewMultiTransferTransaction(gasPrice, gasLimit uint64, states []*ont.State) (*types.MutableTransaction, error)

func (*Ong) NewTransferFromTransaction

func (this *Ong) NewTransferFromTransaction(gasPrice, gasLimit uint64, sender, from, to common.Address, amount uint64) (*types.MutableTransaction, error)

func (*Ong) NewTransferTransaction

func (this *Ong) NewTransferTransaction(gasPrice, gasLimit uint64, from, to common.Address, amount uint64) (*types.MutableTransaction, error)

func (*Ong) NewWithdrawONGTransaction

func (this *Ong) NewWithdrawONGTransaction(gasPrice, gasLimit uint64, address common.Address, amount uint64) (*types.MutableTransaction, error)

func (*Ong) Symbol

func (this *Ong) Symbol() (string, error)

func (*Ong) TotalSupply

func (this *Ong) TotalSupply() (uint64, error)

func (*Ong) Transfer

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

func (*Ong) TransferFrom

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

func (*Ong) UnboundONG

func (this *Ong) UnboundONG(address common.Address) (uint64, error)

func (*Ong) WithdrawONG

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

type Ont

type Ont struct {
	// contains filtered or unexported fields
}

func (*Ont) Allowance

func (this *Ont) Allowance(from, to common.Address) (uint64, error)

func (*Ont) Approve

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

func (*Ont) BalanceOf

func (this *Ont) BalanceOf(address common.Address) (uint64, error)

func (*Ont) Decimals

func (this *Ont) Decimals() (byte, error)

func (*Ont) MultiTransfer

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

func (*Ont) Name

func (this *Ont) Name() (string, error)

func (*Ont) NewApproveTransaction

func (this *Ont) NewApproveTransaction(gasPrice, gasLimit uint64, from, to common.Address, amount uint64) (*types.MutableTransaction, error)

func (*Ont) NewMultiTransferTransaction

func (this *Ont) NewMultiTransferTransaction(gasPrice, gasLimit uint64, states []*ont.State) (*types.MutableTransaction, error)

func (*Ont) NewTransferFromTransaction

func (this *Ont) NewTransferFromTransaction(gasPrice, gasLimit uint64, sender, from, to common.Address, amount uint64) (*types.MutableTransaction, error)

func (*Ont) NewTransferTransaction

func (this *Ont) NewTransferTransaction(gasPrice, gasLimit uint64, from, to common.Address, amount uint64) (*types.MutableTransaction, error)

func (*Ont) Symbol

func (this *Ont) Symbol() (string, error)

func (*Ont) TotalSupply

func (this *Ont) TotalSupply() (uint64, error)

func (*Ont) Transfer

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

func (*Ont) TransferFrom

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

type OntId

type OntId struct {
	// contains filtered or unexported fields
}

func (*OntId) AddAttributes

func (this *OntId) AddAttributes(gasPrice, gasLimit uint64, signer *Account, ontId string, attributes []*DDOAttribute, controller *Controller) (common.Uint256, error)

func (*OntId) AddKey

func (this *OntId) AddKey(gasPrice, gasLimit uint64, ontId string, signer *Account, newPubKey keypair.PublicKey, controller *Controller) (common.Uint256, error)

func (*OntId) ChangeRecovery

func (this *OntId) ChangeRecovery(gasPrice, gasLimit uint64, signer *Account, ontId string, newRecovery, oldRecovery common.Address, controller *Controller) (common.Uint256, error)

func (*OntId) GetAttributes

func (this *OntId) GetAttributes(ontId string) ([]*DDOAttribute, error)

func (*OntId) GetDDO

func (this *OntId) GetDDO(ontId string) (*DDO, error)

func (*OntId) GetKeyState

func (this *OntId) GetKeyState(ontId string, keyIndex int) (string, error)

func (*OntId) GetPublicKeys

func (this *OntId) GetPublicKeys(ontId string) ([]*DDOOwner, error)

func (*OntId) NewAddAttributesTransaction

func (this *OntId) NewAddAttributesTransaction(gasPrice, gasLimit uint64, ontId string, attributes []*DDOAttribute, pubKey keypair.PublicKey) (*types.MutableTransaction, error)

func (*OntId) NewAddKeyTransaction

func (this *OntId) NewAddKeyTransaction(gasPrice, gasLimit uint64, ontId string, newPubKey, pubKey keypair.PublicKey) (*types.MutableTransaction, error)

func (*OntId) NewChangeRecoveryTransaction

func (this *OntId) NewChangeRecoveryTransaction(gasPrice, gasLimit uint64, ontId string, newRecovery, oldRecovery common.Address) (*types.MutableTransaction, error)

func (*OntId) NewRegIDWithAttributesTransaction

func (this *OntId) NewRegIDWithAttributesTransaction(gasPrice, gasLimit uint64, ontId string, pubKey keypair.PublicKey, attributes []*DDOAttribute) (*types.MutableTransaction, error)

func (*OntId) NewRegIDWithPublicKeyTransaction

func (this *OntId) NewRegIDWithPublicKeyTransaction(gasPrice, gasLimit uint64, ontId string, pubKey keypair.PublicKey) (*types.MutableTransaction, error)

func (*OntId) NewRemoveAttributeTransaction

func (this *OntId) NewRemoveAttributeTransaction(gasPrice, gasLimit uint64, ontId string, key []byte, pubKey keypair.PublicKey) (*types.MutableTransaction, error)

func (*OntId) NewRevokeKeyTransaction

func (this *OntId) NewRevokeKeyTransaction(gasPrice, gasLimit uint64, ontId string, removedPubKey, pubKey keypair.PublicKey) (*types.MutableTransaction, error)

func (*OntId) NewSetRecoveryTransaction

func (this *OntId) NewSetRecoveryTransaction(gasPrice, gasLimit uint64, ontId string, recovery common.Address, pubKey keypair.PublicKey) (*types.MutableTransaction, error)

func (*OntId) RegIDWithAttributes

func (this *OntId) RegIDWithAttributes(gasPrice, gasLimit uint64, signer *Account, ontId string, controller *Controller, attributes []*DDOAttribute) (common.Uint256, error)

func (*OntId) RegIDWithPublicKey

func (this *OntId) RegIDWithPublicKey(gasPrice, gasLimit uint64, signer *Account, ontId string, controller *Controller) (common.Uint256, error)

func (*OntId) RemoveAttribute

func (this *OntId) RemoveAttribute(gasPrice, gasLimit uint64, signer *Account, ontId string, removeKey []byte, controller *Controller) (common.Uint256, error)

func (*OntId) RevokeKey

func (this *OntId) RevokeKey(gasPrice, gasLimit uint64, ontId string, signer *Account, removedPubKey keypair.PublicKey, controller *Controller) (common.Uint256, error)

func (*OntId) SetRecovery

func (this *OntId) SetRecovery(gasPrice, gasLimit uint64, signer *Account, ontId string, recovery common.Address, controller *Controller) (common.Uint256, error)

func (*OntId) VerifySignature

func (this *OntId) VerifySignature(ontId string, keyIndex int, controller *Controller) (bool, error)

type Signer

type Signer interface {
	Sign(data []byte) ([]byte, error)
	GetPublicKey() keypair.PublicKey
	GetPrivateKey() keypair.PrivateKey
	GetSigScheme() s.SignatureScheme
}

type Wallet

type Wallet struct {
	Name    string
	Version string
	Scrypt  *keypair.ScryptParam
	Extra   string
	// contains filtered or unexported fields
}

func NewWallet

func NewWallet(path string) *Wallet

func OpenWallet

func OpenWallet(path string) (*Wallet, error)

func (*Wallet) AddAccountData

func (this *Wallet) AddAccountData(accountData *AccountData) error

func (*Wallet) AddIdentity

func (this *Wallet) AddIdentity(identity *Identity) error

func (*Wallet) ChangeAccountPassword

func (this *Wallet) ChangeAccountPassword(address string, oldPassword, newPassword []byte) error

func (*Wallet) DeleteAccount

func (this *Wallet) DeleteAccount(address string) error

func (*Wallet) DeleteIdentity

func (this *Wallet) DeleteIdentity(id string) error

func (*Wallet) ExportAccounts

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

func (*Wallet) GetAccountByAddress

func (this *Wallet) GetAccountByAddress(address string, passwd []byte) (*Account, error)

func (*Wallet) GetAccountByIndex

func (this *Wallet) GetAccountByIndex(index int, passwd []byte) (*Account, error)

Index start from 1

func (*Wallet) GetAccountByLabel

func (this *Wallet) GetAccountByLabel(label string, passwd []byte) (*Account, error)

func (*Wallet) GetAccountCount

func (this *Wallet) GetAccountCount() int

func (*Wallet) GetAccountDataByAddress

func (this *Wallet) GetAccountDataByAddress(address string) (*AccountData, error)

func (*Wallet) GetAccountDataByIndex

func (this *Wallet) GetAccountDataByIndex(index int) (*AccountData, error)

Index start from 1

func (*Wallet) GetAccountDataByLabel

func (this *Wallet) GetAccountDataByLabel(label string) (*AccountData, error)

func (*Wallet) GetDefaultAccount

func (this *Wallet) GetDefaultAccount(passwd []byte) (*Account, error)

func (*Wallet) GetDefaultAccountData

func (this *Wallet) GetDefaultAccountData() (*AccountData, error)

func (*Wallet) GetDefaultIdentity

func (this *Wallet) GetDefaultIdentity() (*Identity, error)

func (*Wallet) GetIdentityById

func (this *Wallet) GetIdentityById(id string) (*Identity, error)

func (*Wallet) GetIdentityByIndex

func (this *Wallet) GetIdentityByIndex(index int) (*Identity, error)

Index start from 1

func (*Wallet) GetIdentityByLabel

func (this *Wallet) GetIdentityByLabel(label string) (*Identity, error)

func (*Wallet) GetIdentityCount

func (this *Wallet) GetIdentityCount() int

func (*Wallet) ImportAccounts

func (this *Wallet) ImportAccounts(accountDatas []*AccountData, passwds [][]byte) error

func (*Wallet) NewAccount

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

func (*Wallet) NewAccountFromWIF

func (this *Wallet) NewAccountFromWIF(wif, passwd []byte) (*Account, error)

func (*Wallet) NewDefaultSettingAccount

func (this *Wallet) NewDefaultSettingAccount(passwd []byte) (*Account, error)

func (*Wallet) NewDefaultSettingIdentity

func (this *Wallet) NewDefaultSettingIdentity(passwd []byte) (*Identity, error)

func (*Wallet) NewIdentity

func (this *Wallet) NewIdentity(keyType keypair.KeyType, curveCode byte, sigScheme s.SignatureScheme, passwd []byte) (*Identity, error)

func (*Wallet) Save

func (this *Wallet) Save() error

func (*Wallet) SetDefaultAccount

func (this *Wallet) SetDefaultAccount(address string) error

func (*Wallet) SetDefaultIdentity

func (this *Wallet) SetDefaultIdentity(id string) error

func (*Wallet) SetIdentityLabel

func (this *Wallet) SetIdentityLabel(id, newLabel string) error

func (*Wallet) SetLabel

func (this *Wallet) SetLabel(address, newLabel string) error

func (*Wallet) SetSigScheme

func (this *Wallet) SetSigScheme(address string, sigScheme s.SignatureScheme) error

type WalletData

type WalletData struct {
	Name       string               `json:"name"`
	Version    string               `json:"version"`
	Scrypt     *keypair.ScryptParam `json:"scrypt"`
	Identities []*IdentityData      `json:"identities,omitempty"`
	Accounts   []*AccountData       `json:"accounts,omitempty"`
	Extra      string               `json:"extra,omitempty"`
}

func NewWalletData

func NewWalletData() *WalletData

func (*WalletData) Clone

func (this *WalletData) Clone() *WalletData

func (*WalletData) Load

func (this *WalletData) Load(path string) error

func (*WalletData) Save

func (this *WalletData) Save(path string) error

Directories

Path Synopsis
* Copyright (C) 2018 The dna Authors * This file is part of The dna library.
* Copyright (C) 2018 The dna Authors * This file is part of The dna library.
* Copyright (C) 2018 The dna Authors * This file is part of The dna library.
* Copyright (C) 2018 The dna Authors * This file is part of The dna library.
* Copyright (C) 2018 The dna Authors * This file is part of The dna library.
* Copyright (C) 2018 The dna Authors * This file is part of The dna library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL