From 5b325c0803a6ab9ef764c89c29d93c7fa0801603 Mon Sep 17 00:00:00 2001 From: LycrusHamster Date: Mon, 10 Feb 2020 15:17:32 +0800 Subject: [PATCH 1/3] update graphql_api.md --- docs/graphql_api.md | 534 +++++++++++++++++++++++++++++--------------- 1 file changed, 353 insertions(+), 181 deletions(-) diff --git a/docs/graphql_api.md b/docs/graphql_api.md index f18568f..f3908cf 100644 --- a/docs/graphql_api.md +++ b/docs/graphql_api.md @@ -1,4 +1,4 @@ -# Huobi-chain GraphQL API +# Muta GraphQL API >[GraphQL](https://graphql.org) is a query language for APIs and a runtime for fulfilling those queries with your existing data. @@ -6,7 +6,7 @@ GraphQL provides a complete and understandable description of the data in your A gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools. -Huobi-chain has embeded a [Graph*i*QL](https://github.com/graphql/graphiql) for checking and calling API. Started a the Huobi-chain +Muta has embeded a [Graph*i*QL](https://github.com/graphql/graphiql) for checking and calling API. Started a the Muta node, and then try open http://127.0.0.1:8000/graphiql in the browser. @@ -16,21 +16,24 @@ node, and then try open http://127.0.0.1:8000/graphiql in the browser. * [Query](#query) * [Mutation](#mutation) * [Objects](#objects) - * [Epoch](#epoch) - * [EpochHeader](#epochheader) + * [Block](#block) + * [BlockHeader](#blockheader) + * [Event](#event) + * [ExecResp](#execresp) + * [Proof](#proof) + * [Receipt](#receipt) + * [ReceiptResponse](#receiptresponse) + * [SignedTransaction](#signedtransaction) + * [Validator](#validator) * [Inputs](#inputs) - * [InputDeployAction](#inputdeployaction) * [InputRawTransaction](#inputrawtransaction) * [InputTransactionEncryption](#inputtransactionencryption) - * [InputTransferAction](#inputtransferaction) - * [Enums](#enums) - * [ContractType](#contracttype) * [Scalars](#scalars) * [Address](#address) - * [Balance](#balance) * [Boolean](#boolean) * [Bytes](#bytes) * [Hash](#hash) + * [Int](#int) * [String](#string) * [Uint64](#uint64) @@ -48,119 +51,112 @@ node, and then try open http://127.0.0.1:8000/graphiql in the browser. -getLatestEpoch -Epoch! +getBlock +Block! -Get the latest epoch +Get the block -epochId +height Uint64 -getBalance -Balance! +getTransaction +SignedTransaction! -Get the asset balance of an account +Get the transaction by hash -address -Address! +txHash +Hash! -id -Hash! +getReceipt +Receipt! -The asset id. Asset is the first-class in Huobi-chain, this means that your assets can be more than one in Huobi-chain, and the UDT(User Defined Token) will be supported in the future +Get the receipt by transaction hash -epochId -Uint64 +txHash +Hash! - - - -## Mutation - - - - - - - - - - - - + + - - + + - - + + - - + + - - - + + + - - + + - - + + - - + + + +
FieldArgumentTypeDescription
sendTransferTransactionHash!queryServiceExecResp! -Send a transfer transaction to the blockchain. +query service
inputRawInputRawTransaction!heightUint64
inputActionInputTransferAction!cyclesLimitUint64
inputEncryptionInputTransactionEncryption!cyclesPriceUint64
sendDeployTransactionHash! - -Send deployment contract transaction to the blockchain. - -callerAddress!
inputRawInputRawTransaction!serviceNameString!
inputActionInputDeployAction!methodString!
inputEncryptionInputTransactionEncryption!payloadString!
+ +## Mutation + + + + + + + + + + - + @@ -169,17 +165,12 @@ DON'T use it in production! This is just for development. - - - - - - - + + - + - - - - - @@ -210,9 +196,9 @@ DON'T use it in production! This is just for development. ## Objects -### Epoch +### Block -Epoch is a single digital record created within a blockchain. Each epoch contains a record of the previous Epoch, and when linked together these become the “chain”.An epoch is always composed of header and body. +Block is a single digital record created within a blockchain. Each block contains a record of the previous Block, and when linked together these become the “chain”.A block is always composed of header and body.
FieldArgumentTypeDescription
sendUnsafeTransferTransaction ⚠️sendTransaction Hash! -

⚠️ DEPRECATED

-
-DON'T use it in production! This is just for development. +send transaction -
inputActionInputTransferAction!
inputPrivkeyBytes!inputEncryptionInputTransactionEncryption!
sendUnsafeDeployTransaction ⚠️unsafeSendTransaction ⚠️ Hash!

⚠️ DEPRECATED

@@ -196,11 +187,6 @@ DON'T use it in production! This is just for development.
inputActionInputDeployAction!
inputPrivkey Bytes!
@@ -226,10 +212,10 @@ Epoch is a single digital record created within a blockchain. Each epoch contain - + @@ -238,16 +224,16 @@ The header section of an epoch
headerEpochHeader!BlockHeader! -The header section of an epoch +The header section of a block
[Hash!]! -The body section of an epoch +The body section of a block
-### EpochHeader +### BlockHeader -An epoch header is like the metadata of an epoch. +A block header is like the metadata of a block. @@ -269,11 +255,20 @@ Identifier of a chain in order to prevent replay attacks across channels - + + + + + + @@ -282,7 +277,7 @@ Known as the block height like other blockchain @@ -291,7 +286,7 @@ The hash of the serialized previous epoch @@ -333,7 +328,7 @@ The merkle roots of receipts - + + + + + + + + + + +
epochIdheight Uint64! -Known as the block height like other blockchain +block height + +
execHeightUint64! + +The height to which the block has been executed
Hash! -The hash of the serialized previous epoch +The hash of the serialized previous block
Uint64! -A timestamp that records when the epoch was created +A timestamp that records when the block was created
cyclesUsedUint64![Uint64!]! The sum of all transactions costs @@ -345,11 +340,16 @@ The sum of all transactions costs Address! -The address descirbed who packed the epoch +The address descirbed who packed the block
proofProof!
validatorVersion Uint64! @@ -358,152 +358,293 @@ The version of validator is designed for cross chain
validators[Validator!]!
-## Inputs - -### InputDeployAction - -The deploy transfer transaction +### Event - + + - - - + + + - - - + + + + +
FieldFieldArgument Type Description
codeBytes! - -Encoded contract code - -serviceString!
contractTypeContractType! +dataString!
-The type of contract +### ExecResp - + + + + + + + + + + + + + + + + + + +
FieldArgumentTypeDescription
retString!
isErrorBoolean!
-### InputRawTransaction +### Proof -There was many types of transaction in Huobi-chain, A transaction often require computing resources or write data to chain,these resources are valuable so we need to pay some token for them.InputRawTransaction describes information above +The verifier of the block header proved - + + - - - + + + - + - + - + - + + + + + + + + + + + + +
FieldFieldArgument Type Description
chainIdHash! - -Identifier of the chain. - -heightUint64!
feeCycleround Uint64! - -Mostly like the gas limit in Ethereum, describes the fee that you are willing to pay the highest price for the transaction - -
feeAssetIdblockHash Hash! +
signatureBytes!
bitmapBytes!
-asset type +### Receipt - + + + + + + + + + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + +
FieldArgumentTypeDescription
noncestateRoot Hash! - -Every transaction has its own id, unlike Ethereum's nonce,the nonce in Huobi-chain is an hash - -
timeoutheight Uint64! +
txHashHash!
cyclesUsedUint64!
events[Event!]!
responseReceiptResponse!
-For security and performance reasons, Huobi-chain will only deal with trade request over a period of time,the `timeout` should be `timeout > current_epoch_height` and `timeout < current_epoch_height + timeout_gap`,the `timeout_gap` generally equal to 20. +### ReceiptResponse - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FieldArgumentTypeDescription
serviceNameString!
methodString!
retString!
isErrorBoolean!
-### InputTransactionEncryption - -Signature of the transaction +### SignedTransaction - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + + +
FieldFieldArgument Type Description
chainIdHash!
cyclesLimitUint64!
cyclesPriceUint64!
nonceHash!
timeoutUint64!
serviceNameString!
methodString!
payloadString!
txHash Hash! - -The digest of the transaction - -
pubkey Bytes! - -The public key of transfer - -
signature Bytes! +
-The signature of the transaction +### Validator - +Validator address set + + + + + + + + + + + + + + + + + + + + + + + + +
FieldArgumentTypeDescription
addressAddress!
proposeWeightInt!
voteWeightInt!
-### InputTransferAction +## Inputs -The action of transfer transaction +### InputRawTransaction + +There was many types of transaction in Muta, A transaction often require computing resources or write data to chain,these resources are valuable so we need to pay some token for them.InputRawTransaction describes information above @@ -515,68 +656,101 @@ The action of transfer transaction - - + + - + + + + + + + + + + + - - + + + + + + + + + + + + + + + + +
carryingAmountBalance!chainIdHash! -The amount of the transfer +Identifier of the chain.
carryingAssetIdcyclesLimitUint64! + +Mostly like the gas limit in Ethereum, describes the fee that you are willing to pay the highest price for the transaction + +
cyclesPriceUint64!
nonce Hash! -The asset of of the transfer +Every transaction has its own id, unlike Ethereum's nonce,the nonce in Muta is an hash
receiverAddress!timeoutUint64! -The receiver of the transfer +For security and performance reasons, Muta will only deal with trade request over a period of time,the `timeout` should be `timeout > current_block_height` and `timeout < current_block_height + timeout_gap`,the `timeout_gap` generally equal to 20.
serviceNameString!
methodString!
payloadString!
-## Enums - -### ContractType +### InputTransactionEncryption -According to different purposes, Huobi-chain has many contract type +Signature of the transaction - + + + + - + + - + + - + + @@ -587,11 +761,7 @@ Library contract often providing reusable and immutable function ### Address -21 bytes of account address, the first bytes of which is the identifier. - -### Balance - -uint256 +20 bytes of account address ### Boolean @@ -603,6 +773,8 @@ Bytes corresponding hex string. The output digest of Keccak hash function +### Int + ### String ### Uint64 From 12ff396022c9d46995b0821759f3a5d155f45445 Mon Sep 17 00:00:00 2001 From: LycrusHamster Date: Mon, 10 Feb 2020 22:31:23 +0800 Subject: [PATCH 2/3] fix(doc):graphql_api.md href error --- docs/graphql_api.md | 162 ++++++++++++++++++++++---------------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/docs/graphql_api.md b/docs/graphql_api.md index f3908cf..40a9b48 100644 --- a/docs/graphql_api.md +++ b/docs/graphql_api.md @@ -6,7 +6,7 @@ GraphQL provides a complete and understandable description of the data in your A gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools. -Muta has embeded a [Graph*i*QL](https://github.com/graphql/graphiql) for checking and calling API. Started a the Muta +Muta has embeded a [Graph**i**QL](https://github.com/graphql/graphiql) for checking and calling API. Started a the Muta node, and then try open http://127.0.0.1:8000/graphiql in the browser. @@ -52,7 +52,7 @@ node, and then try open http://127.0.0.1:8000/graphiql in the browser. - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -152,7 +152,7 @@ query service - + - + - + - + - + - + @@ -212,7 +212,7 @@ Block is a single digital record created within a blockchain. Each block contain - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -380,12 +380,12 @@ The version of validator is designed for cross chain - + - + @@ -405,12 +405,12 @@ The version of validator is designed for cross chain - + - + @@ -432,27 +432,27 @@ The verifier of the block header proved - + - + - + - + - + @@ -472,32 +472,32 @@ The verifier of the block header proved - + - + - + - + - + - + @@ -517,22 +517,22 @@ The verifier of the block header proved - + - + - + - + @@ -552,57 +552,57 @@ The verifier of the block header proved - + - + - + - + - + - + - + - + - + - + - + @@ -624,17 +624,17 @@ Validator address set - + - + - + @@ -657,7 +657,7 @@ There was many types of transaction in Muta, A transaction often require computi - + - + - + - + - + - + - + - + @@ -729,7 +729,7 @@ Signature of the transaction - + - + - +
Value
FieldType Description
ASSETtxHashHash! -Asset contract often use for creating User Defined Asset(also known as UDT(User Defined Token)) +The digest of the transaction
APPpubkeyBytes! -App contract often use for creating DAPP(Decentralized APPlication) +The public key of transfer
LIBRARYsignatureBytes! -Library contract often providing reusable and immutable function +The signature of the transaction
getBlockBlock!Block! Get the block @@ -61,12 +61,12 @@ Get the block
heightUint64Uint64
getTransactionSignedTransaction!SignedTransaction! Get the transaction by hash @@ -75,12 +75,12 @@ Get the transaction by hash
txHashHash!Hash!
getReceiptReceipt!Receipt! Get the receipt by transaction hash @@ -89,12 +89,12 @@ Get the receipt by transaction hash
txHashHash!Hash!
queryServiceExecResp!ExecResp! query service @@ -103,37 +103,37 @@ query service
heightUint64Uint64
cyclesLimitUint64Uint64
cyclesPriceUint64Uint64
callerAddress!Address!
serviceNameString!String!
methodString!String!
payloadString!String!
sendTransactionHash!Hash! send transaction @@ -161,17 +161,17 @@ send transaction
inputRawInputRawTransaction!InputRawTransaction!
inputEncryptionInputTransactionEncryption!InputTransactionEncryption!
unsafeSendTransaction ⚠️Hash!Hash!

⚠️ DEPRECATED

@@ -183,12 +183,12 @@ DON'T use it in production! This is just for development.
inputRawInputRawTransaction!InputRawTransaction!
inputPrivkeyBytes!Bytes!
headerBlockHeader!BlockHeader! The header section of a block @@ -221,7 +221,7 @@ The header section of a block
orderedTxHashes[Hash!]![Hash!]! The body section of a block @@ -247,7 +247,7 @@ A block header is like the metadata of a block.
chainIdHash!Hash! Identifier of a chain in order to prevent replay attacks across channels @@ -256,7 +256,7 @@ Identifier of a chain in order to prevent replay attacks across channels
heightUint64!Uint64! block height @@ -265,7 +265,7 @@ block height
execHeightUint64!Uint64! The height to which the block has been executed @@ -274,7 +274,7 @@ The height to which the block has been executed
preHashHash!Hash! The hash of the serialized previous block @@ -283,7 +283,7 @@ The hash of the serialized previous block
timestampUint64!Uint64! A timestamp that records when the block was created @@ -292,7 +292,7 @@ A timestamp that records when the block was created
orderRootHash!Hash! The merkle root of ordered transactions @@ -301,7 +301,7 @@ The merkle root of ordered transactions
confirmRoot[Hash!]![Hash!]! The merkle roots of all the confirms @@ -310,7 +310,7 @@ The merkle roots of all the confirms
stateRootHash!Hash! The merkle root of state root @@ -319,7 +319,7 @@ The merkle root of state root
receiptRoot[Hash!]![Hash!]! The merkle roots of receipts @@ -328,7 +328,7 @@ The merkle roots of receipts
cyclesUsed[Uint64!]![Uint64!]! The sum of all transactions costs @@ -337,7 +337,7 @@ The sum of all transactions costs
proposerAddress!Address! The address descirbed who packed the block @@ -346,12 +346,12 @@ The address descirbed who packed the block
proofProof!Proof!
validatorVersionUint64!Uint64! The version of validator is designed for cross chain @@ -360,7 +360,7 @@ The version of validator is designed for cross chain
validators[Validator!]![Validator!]!
serviceString!String!
dataString!String!
retString!String!
isErrorBoolean!Boolean!
heightUint64!Uint64!
roundUint64!Uint64!
blockHashHash!Hash!
signatureBytes!Bytes!
bitmapBytes!Bytes!
stateRootHash!Hash!
heightUint64!Uint64!
txHashHash!Hash!
cyclesUsedUint64!Uint64!
events[Event!]![Event!]!
responseReceiptResponse!ReceiptResponse!
serviceNameString!String!
methodString!String!
retString!String!
isErrorBoolean!Boolean!
chainIdHash!Hash!
cyclesLimitUint64!Uint64!
cyclesPriceUint64!Uint64!
nonceHash!Hash!
timeoutUint64!Uint64!
serviceNameString!String!
methodString!String!
payloadString!String!
txHashHash!Hash!
pubkeyBytes!Bytes!
signatureBytes!Bytes!
addressAddress!Address!
proposeWeightInt!Int!
voteWeightInt!Int!
chainIdHash!Hash! Identifier of the chain. @@ -666,7 +666,7 @@ Identifier of the chain.
cyclesLimitUint64!Uint64! Mostly like the gas limit in Ethereum, describes the fee that you are willing to pay the highest price for the transaction @@ -675,12 +675,12 @@ Mostly like the gas limit in Ethereum, describes the fee that you are willing to
cyclesPriceUint64!Uint64!
nonceHash!Hash! Every transaction has its own id, unlike Ethereum's nonce,the nonce in Muta is an hash @@ -689,7 +689,7 @@ Every transaction has its own id, unlike Ethereum's nonce,the nonce in Muta is a
timeoutUint64!Uint64! For security and performance reasons, Muta will only deal with trade request over a period of time,the `timeout` should be `timeout > current_block_height` and `timeout < current_block_height + timeout_gap`,the `timeout_gap` generally equal to 20. @@ -698,17 +698,17 @@ For security and performance reasons, Muta will only deal with trade request ove
serviceNameString!String!
methodString!String!
payloadString!String!
txHashHash!Hash! The digest of the transaction @@ -738,7 +738,7 @@ The digest of the transaction
pubkeyBytes!Bytes! The public key of transfer @@ -747,7 +747,7 @@ The public key of transfer
signatureBytes!Bytes! The signature of the transaction From 19e5afeabcbfe1839d818768923e341997c6fcf3 Mon Sep 17 00:00:00 2001 From: LycrusHamster Date: Thu, 13 Feb 2020 09:41:44 +0800 Subject: [PATCH 3/3] doc:update doc --- docs/js_sdk.md | 25 +++++-------------------- docs/js_sdk_examples.md | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/docs/js_sdk.md b/docs/js_sdk.md index 60870db..e4d13c5 100644 --- a/docs/js_sdk.md +++ b/docs/js_sdk.md @@ -397,7 +397,7 @@ UDT是一种基于数量的无差别资产,类似于以太坊ERC20 token 构建一个Asset ```js async function example(){ - const createdAsset = await service.createAsset({ + const createdAsset = await service.create_asset({ name: 'LOVE_COIN', supply, symbol: 'LUV' @@ -415,29 +415,14 @@ async function example(){ ``` -##### getAsset -根据asset_id,查询对应的asset -```js -async function example(){ - const asset = await service.getAsset(createdAsset.assetId); - /*return data: - Asset { - asset_id: Hash; - name: string; - symbol: string; - supply: number; - issuer: Address; - } - */ -} - -``` - ##### getBalance 获取一个某一用户在某一资产下的余额 ```js async function example(){ - const balance = await service.getBalance(createdAsset.assetId, account.address); + const assetId = createdAsset.response.ret.id; + const { + ret: { balance }, + } = await service.get_balance({asset_id: assetId, user:account.address}); } ``` diff --git a/docs/js_sdk_examples.md b/docs/js_sdk_examples.md index 6ad5180..71dff5d 100644 --- a/docs/js_sdk_examples.md +++ b/docs/js_sdk_examples.md @@ -421,22 +421,22 @@ export interface Asset { 接下来就非常简单了,我们直接创建一个资产,参数类型和之前的相同,不再赘述: ```typescript - const createdAsset = await service.createAsset({ - name: 'LOVE_COIN', - supply: 1314, - symbol: 'LUV', - }); - const assetId = createdAsset.asset_id; -``` - -我们通过asset_id来查询一个资产的状态: -```typescript - const asset = await service.getAsset(assetId); + const createdAsset = await service.create_asset({ + name: 'LOVE_COIN', + supply, + symbol: 'LUV', + }); + const assetId = createdAsset.response.ret.id; ``` 查询一下某个用户的余额: ```typescript - const balance = await service.getBalance(assetId, '0x2000000000000000000000000000000000000000'); + const { + ret: { balance : balance0x2000000000000000000000000000000000000000}, + }= await service.get_balance({ + asset_id : assetId, + user : to, + }); ``` 最后是向某个用户发送一定数量的UDT,这里是LOVE_COIN