- Go SDK For Poly
- 1. Overview
- 2. How to use?
- 2.1 Block Chain API
- 2.1.1 Get current block height
- 2.1.2 Get current block hash
- 2.1.3 Get block by height
- 2.1.4 Get block by hash
- 2.1.5 Get transaction by transaction hash
- 2.1.6 Get block hash by block height
- 2.1.7 Get block height by transaction hash
- 2.1.8 Get transaction hashes of block by block height
- 2.1.9 Get storage value of smart contract key
- 2.1.10 Get smart contract by contract address
- 2.1.11 Get smart contract event by transaction hash
- 2.1.12 Get all of smart contract events of block by block height
- 2.1.13 Get block merkle proof by transaction hash
- 2.1.14 Get transaction state of transaction pool
- 2.1.15 Get transaction count in transaction pool
- 2.1.16 Get version of Poly
- 2.1.17 Get network id of Poly
- 2.1.18 Send transaction to Poly
- 2.19 Prepare execute transaction
- 2.2 Wallet API
- 2.2.1 Create or Open Wallet
- 2.2.2 Save Wallet
- 2.2.3 New account
- 2.2.4 New default setting account
- 2.2.5 New account from wif private key
- 2.2.5 Delete account
- 2.2.5 Get default account
- 2.2.6 Set default account
- 2.2.7 Get account by address
- 2.2.8 Get account by label
- 2.2.9 Get account by index
- 2.2.10 Get account count of wallet
- 2.2.11 Get default account data
- 2.2.12 Get account data by address
- 2.2.13 Get account data by label
- 2.2.14 Get account data by index
- 2.2.15 Set account label
- 2.2.16 Set signature scheme of account
- 2.2.17 Change account password
- 2.2.18 Import account to wallet
- 2.2.19 Export account to a new wallet
- 2.3 CrossChain API
- 2.3.1 Commit crosschain transaction proof of sidechain to Poly
- 2.3.2 Register a sidechain to Poly
- 2.3.3 Approve the sidechain registration
- 2.3.4 Update sidechain information on Poly
- 2.3.5 Approve the update of sidechain information
- 2.3.6 Make a proposal to remove side chain
- 2.3.7 Approve the proposal to remove side chain
- 2.3.8 Register the redeem script for BTC vendor
- 2.3.9 Set parameters for vendor's BTC-unlocking transactions
- 2.3.10 Register candidate for new consensus epoch
- 2.3.11 Approve registration of candidate
- 2.3.12 Cancel the registration of candidate
- 2.3.13 Regect the registration of candidate
- 2.3.14 Pull a node into black list
- 2.3.15 Pull a node out of black list
- 2.3.16 Update poly consensus configuration
- 2.3.17 Register a wallet as relayer
- 2.3.18 Approve registration of a relayer
- 2.3.19 Remove an account from relayer list
- 2.3.20 Approve the remove of a relayer
- 2.3.21 Commit Dpos to switch consensus epoch
- 2.1 Block Chain API
- Contributing
This is a comprehensive Go library for the Poly blockchain. Currently, it supports local wallet management, deployment/invoking of smart contracts and communication with the Poly Blockchain. In the future it will also support more rich functions and applications.
First, create an PolySDK
instance with the NewPolySdk
method.
polySdk := NewPolySdk()
Next, create an rpc, rest or websocket client.
polySdk.NewRpcClient().SetAddress("http://localhost:20336")
Then, call the rpc server through the sdk instance.
polySdk.GetCurrentBlockHeight() (uint32, error)
polySdk.GetCurrentBlockHash() (common.Uint256, error)
polySdk.GetBlockByHeight(height uint32) (*types.Block, error)
polySdk.GetBlockByHash(blockHash string) (*types.Block, error)
polySdk.GetTransaction(txHash string) (*types.Transaction, error)
polySdk.GetBlockHash(height uint32) (common.Uint256, error)
polySdk.GetBlockHeightByTxHash(txHash string) (uint32, error)
polySdk.GetBlockTxHashesByHeight(height uint32) (*sdkcom.BlockTxHashes, error)
polySdk.GetStorage(contractAddress string, key []byte) ([]byte, error)
polySdk.GetSmartContract(contractAddress string) (*sdkcom.SmartContract, error)
polySdk.GetSmartContractEvent(txHash string) (*sdkcom.SmartContactEvent, error)
polySdk.GetSmartContractEventByHeight(height uint32) ([]*sdkcom.SmartContactEvent, error)
polySdk.GetMerkleProof(txHash string) (*sdkcom.MerkleProof, error)
polySdk.GetMemPoolTxState(txHash string) (*sdkcom.MemPoolTxState, error)
polySdk.GetMemPoolTxCount() (*sdkcom.MemPoolTxCount, error)
polySdk.GetVersion() (string, error)
polySdk.GetNetworkId() (uint32, error)
polySdk.SendTransaction(mutTx *types.MutableTransaction) (common.Uint256, error)
polySdk.PreExecTransaction(mutTx *types.MutableTransaction) (*sdkcom.PreExecResult, error)
wa, err := OpenWallet(path string) (*Wallet, error)
If the path is for an existing wallet file, then open the wallet, otherwise return error.
wa.Save() error
Note that any modifications of the wallet require calling Save()
in
order for the changes to persist.
wa.NewAccount(keyType keypair.KeyType, curveCode byte, sigScheme s.SignatureScheme, passwd []byte) (*Account, error)
Poly 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.
Poly 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.
wa.NewDefaultSettingAccount(passwd []byte) (*Account, error)
The default settings for an account uses ECDSA with SHA256withECDSA as signature scheme.
wa.NewAccountFromWIF(wif, passwd []byte) (*Account, error)
wa.DeleteAccount(address string) error
wa.GetDefaultAccount(passwd []byte) (*Account, error)
wa.SetDefaultAccount(address string) error
wa.GetAccountByAddress(address string, passwd []byte) (*Account, error)
wa.GetAccountByLabel(label string, passwd []byte) (*Account, error)
wa.GetAccountByIndex(index int, passwd []byte) (*Account, error)
Note that indexes start from 1.
wa.GetAccountCount() int
wa.GetDefaultAccountData() (*AccountData, error)
wa.GetAccountDataByAddress(address string) (*AccountData, error)
wa.GetAccountDataByLabel(label string) (*AccountData, error)
wa.GetAccountDataByIndex(index int) (*AccountData, error)
Note that indexes start from 1.
wa.SetLabel(address, newLabel string) error
Note that label cannot duplicate.
wa.SetSigScheme(address string, sigScheme s.SignatureScheme) error
wa.ChangeAccountPassword(address string, oldPassword, newPassword []byte) error
wa.ImportAccounts(accountDatas []*AccountData, passwds [][]byte) error
wa.ExportAccounts(path string, accountDatas []*AccountData, passwds [][]byte, newScrypts ...*keypair.ScryptParam) (*Wallet, error)
polySdk.Native.Ccm.ImportOuterTransfer(sourceChainId uint64, txData []byte, height uint32, proof []byte, relayerAddress []byte, HeaderOrCrossChainMsg []byte, signer *Account) (common.Uint256, error)
polySdk.Native.Scm.RegisterSideChain(address common.Address, chainId, router uint64, name string,
blocksToWait uint64, CMCCAddress []byte, signer *Account) (common.Uint256, error)
polySdk.Native.Scm.ApproveRegisterSideChain(chainId uint64, signer *Account) (common.Uint256, error)
polySdk.Native.Scm.UpdateSideChain(address common.Address, chainId, router uint64, name string,
blocksToWait uint64, CMCCAddress []byte, signer *Account) (common.Uint256, error)
polySdk.Native.Scm.ApproveUpdateSideChain(chainId uint64, signer *Account) (common.Uint256, error)
polySdk.Native.Scm.QuitSideChain(chainId uint64, signer *Account) (common.Uint256, error)
polySdk.Native.Scm.ApproveQuitSideChain(chainId uint64, signer *Account) (common.Uint256, error)
polySdk.Native.Scm.RegisterRedeem(redeemChainID, contractChainID uint64, redeem, contractAddress []byte, cVersion uint64, signs [][]byte, signer *Account) (common.Uint256, error)
polySdk.Native.Scm.SetBtcTxParam(redeem []byte, redeemId, feeRate, minChange, pver uint64, sigArr [][]byte, signer *Account) (common.Uint256, error)
polySdk.Native.Nm.RegisterCandidate(peerPubkey string, signer *Account) (common.Uint256, error)
polySdk.Native.Nm.ApproveCandidate(peerPubkey string, signer *Account) (common.Uint256, error)
polySdk.Native.Nm.UnRegisterCandidate(peerPubkey string, signer *Account) (common.Uint256, error)
polySdk.Native.Nm.RejectCandidate(peerPubkey string, signer *Account) (common.Uint256, error)
polySdk.Native.Nm.BlackNode(peerPubkeyList []string, signer *Account) (common.Uint256, error)
polySdk.Native.Nm.WhiteNode(peerPubkey string, signer *Account) (common.Uint256, error)
polySdk.Native.Nm.UpdateConfig(blockMsgDelay, hashMsgDelay, peerHandshakeTimeout, maxBlockChangeView uint32, signers []*Account) (common.Uint256, error)
polySdk.Native.Rm.RegisterRelayer(addressList []common.Address, signer *Account) (common.Uint256, error)
polySdk.Native.Rm.ApproveRegisterRelayer(applyID uint64, signer *Account) (common.Uint256, error)
polySdk.Native.Rm.RemoveRelayer(addressList []common.Address, signer *Account) (common.Uint256, error)
polySdk.Native.Rm.ApproveRemoveRelayer(removeID uint64, signer *Account) (common.Uint256, error)
polySdk.Native.Nm.CommitDpos(signers []*Account) (common.Uint256, error)
Can I contribute patches to the Poly 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 Poly 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
The Poly 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.