Filecoin 백서

Filecoin

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 52쪽 중 46쪽

contracts/v0.8/tests/market.test.sol). ```solidity pragma solidity ^0.8.18; import "../MarketAPI.sol"; import "../types/MarketTypes.sol"; import "../utils/Errors.sol"; contract MarketApiTest { function add_balance(CommonTypes.FilAddress memory providerOrClient, uint256 value) public payable { (int256 exit_code, ) = MarketAPI.addBalance(providerOrClient, value); Errors.revertOnError(exit_code); } function withdraw_balance(MarketTypes.WithdrawBalanceParams memory params) public returns (CommonTypes.BigInt memory) { (int256 exit_code, CommonTypes.BigInt memory result) = MarketAPI.withdrawBalance(params); Errors.revertOnError(exit_code); return result; } function get_balance(CommonTypes.FilAddress memory addr) public view returns (MarketTypes.GetBalanceReturn memory) { (int256 exit_code, MarketTypes.GetBalanceReturn memory result) = MarketAPI.getBalance(addr); Errors.revertOnError(exit_code); return result; } function get_deal_data_commitment(uint64 dealID) public view returns (MarketTypes.GetDealDataCommitmentReturn memory) { (int256 exit_code, MarketTypes.GetDealDataCommitmentReturn memory result) = MarketAPI.getDealDataCommitment(dealID); Errors.revertOnError(exit_code); return result; } function get_deal_client(uint64 dealID) public view returns (uint64) { (int256 exit_code, uint64 result) = MarketAPI.getDealClient(dealID); Errors.revertOnError(exit_code); return result; } function get_deal_provider(uint64 dealID) public view returns (uint64) { (int256 exit_code, uint64 result) = MarketAPI.getDealProvider(dealID); Errors.revertOnError(exit_code); return result; } function get_deal_label(uint64 dealID) public view returns (CommonTypes.DealLabel memory) { (int256 exit_code, CommonTypes.DealLabel memory result) = MarketAPI.getDealLabel(dealID); Errors.revertOnError(exit_code); return result; } function get_deal_term(uint64 dealID) public view returns (MarketTypes.GetDealTermReturn memory) { (int256 exit_code, MarketTypes.GetDealTermReturn memory result) = MarketAPI.getDealTerm(dealID); Errors.revertOnError(exit_code); return result; } function get_deal_total_price(uint64 dealID) public view returns (CommonTypes.BigInt memory) { (int256 exit_code, CommonTypes.BigInt memory result) = MarketAPI.getDealTotalPrice(dealID); Errors.revertOnError(exit_code); return result; } function get_deal_client_collateral(uint64 dealID) public view returns (CommonTypes.BigInt memory) { (int256 exit_code, CommonTypes.BigInt memory result) = MarketAPI.getDealClientCollateral(dealID); Errors.revertOnError(exit_code); return result; } function get_deal_provider_collateral(uint64 dealID) public view returns (CommonTypes.BigInt memory) { (int256 exit_code, CommonTypes.BigInt memory result) = MarketAPI.getDealProviderCollateral(dealID); Errors.revertOnError(exit_code); return result; } function get_deal_verified(uint64 dealID) public view returns (bool) { (int256 exit_code, bool result) = MarketAPI.getDealVerified(dealID); Errors.revertOnError(exit_code); return result; } function get_deal_activation(uint64 dealID) public view returns (MarketTypes.GetDealActivationReturn memory) { (int256 exit_code, MarketTypes.GetDealActivationReturn memory result) = MarketAPI.getDealActivation(dealID); Errors.revertOnError(exit_code); return result; } function publish_storage_deals(MarketTypes.PublishStorageDealsParams memory params) public returns (MarketTypes.PublishStorageDealsReturn memory) { (int256 exit_code, MarketTypes.PublishStorageDealsReturn memory result) = MarketAPI.publishStorageDeals(params); Errors.revertOnError(exit_code); return result; } } ``` ### Call the miner actor The following example imports the Miner actor library and creates a callable method for each of the [available actor methods](#call-the-miner-actor). For the full code, see [the GitHub repository](https://github.com/filecoin-project/filecoin-solidity/blob/master/contracts/v0.8/tests/miner.test.sol). ```solidity pragma solidity ^0.8.18; import "../MinerAPI.sol"; import "../types/MinerTypes.sol"; import "../utils/Errors.sol"; contract MinerApiTest { function get_owner(CommonTypes.FilActorId target) public view returns (MinerTypes.GetOwnerReturn memory) { (int256 exit_code, MinerTypes.GetOwnerReturn memory result) = MinerAPI.getOwner(target); Errors.revertOnError(exit_code); return result; } function change_owner_address(CommonTypes.FilActorId target, CommonTypes.FilAddress memory addr) public { int256 exit_code = MinerAPI.changeOwnerAddress(target, addr); Errors.revertOnError(exit_code); } function is_controlling_address(CommonTypes.FilActorId target, CommonTypes.FilAddress memory addr) public view returns (bool) { (int256 exit_code, bool result) = MinerAPI.isControllingAddress(target, addr); Errors.revertOnError(exit_code); return result; } function get_sector_size(CommonTypes.FilActorId target) public view returns (uint64) { (int256 exit_code, uint64 result) = MinerAPI.getSectorSize(target); Errors.revertOnError(exit_code); return result; } function get_available_balance(CommonTypes.FilActorId target) public view returns (CommonTypes.BigInt memory) { (int256 exit_code, CommonTypes.BigInt memory result) = MinerAPI.getAvailableBalance(target); Errors.revertOnError(exit_code); return result; } function get_vesting_funds(CommonTypes.FilActorId target) public view returns (MinerTypes.VestingFunds[] memory) { (int256 exit_code, MinerTypes.VestingFunds[] memory result) = MinerAPI.getVestingFunds(target); Errors.revertOnError(exit_code); return result; } function change_beneficiary(CommonTypes.FilActorId target, MinerTypes.ChangeBeneficiaryParams memory params) public { int256 exit_code = MinerAPI.changeBeneficiary(target, params); Errors.revertOnError(exit_code); } function get_beneficiary(CommonTypes.FilActorId target) public view returns (MinerTypes.GetBeneficiaryReturn memory) { (int256 exit_code, MinerTypes.GetBeneficiaryReturn memory result) = MinerAPI.getBeneficiary(target); Errors.revertOnError(exit_code); return result; } function change_worker_address(CommonTypes.FilActorId target, MinerTypes.ChangeWorkerAddressParams memory params) public { int256 exit_code = MinerAPI.changeWorkerAddress(target, params); Errors.revertOnError(exit_code); } function change_peer_id(CommonTypes.FilActorId target, CommonTypes.FilAddress memory newId) public { int256 exit_code = MinerAPI.changePeerId(target, newId); Errors.revertOnError(exit_code); } function change_multiaddresses(CommonTypes.FilActorId target, CommonTypes.FilAddress[] memory new_multi_addrs) public { int256 exit_code = MinerAPI.changeMultiaddresses(target, new_multi_addrs); Errors.revertOnError(exit_code); } function repay_debt(CommonTypes.FilActorId target) public { int256 exit_code = MinerAPI.repayDebt(target); Errors.revertOnError(exit_code); } function confirm_change_worker_address(CommonTypes.FilActorId target) public { int256 exit_code = MinerAPI.confirmChangeWorkerAddress(target); Errors.revertOnError(exit_code); } function get_peer_id(CommonTypes.FilActorId target) public view returns (CommonTypes.FilAddress memory) { (int256 exit_code, CommonTypes.FilAddress memory result) = MinerAPI.getPeerId(target); Errors.revertOnError(exit_code); return result; } function get_multiaddresses(CommonTypes.FilActorId target) public view returns (CommonTypes.FilAddress[] memory) { (int256 exit_code, CommonTypes.FilAddress[] memory result) = MinerAPI.getMultiaddresses(target); Errors.revertOnError(exit_code); return result; } function withdraw_balance(CommonTypes.FilActorId target, CommonTypes.BigInt memory amount) public returns (CommonTypes.BigInt memory) { (int256 exit_code, CommonTypes.BigInt memory result) = MinerAPI.withdrawBalance(target, amount); Errors.revertOnError(exit_code); return result; } } ``` ### Call the storage power actor The following example imports the Storage power actor library and creates a callable method for each of the [available actor methods](#call-the-storage-power-actor). For the full code, see [the GitHub repository](https://github.com/filecoin-project/filecoin-solidity/blob/master/contracts/v0.8/tests/power.test.sol). ```solidity pragma solidity ^0.8.18; import "../types/PowerTypes.sol"; import "../types/CommonTypes.sol"; import "../PowerAPI.sol"; import "../utils/Errors.sol"; contract PowerApiTest { function create_miner(PowerTypes.CreateMinerParams memory params, uint256 value) public payable returns (PowerTypes.CreateMinerReturn memory) { (int256 exit_code, PowerTypes.CreateMinerReturn memory result) = PowerAPI.createMiner(params, value); Errors.revertOnError(exit_code); return result; } function miner_count() public view returns (uint64) { (int256 exit_code, uint64 result) = PowerAPI.minerCount(); Errors.revertOnError(exit_code); return result; } function miner_consensus_count() public view returns (int64) { (int256 exit_code, int64 result) = PowerAPI.minerConsensusCount(); Errors.revertOnError(exit_code); return result; } function network_raw_power() public view returns (CommonTypes.BigInt memory) { (int256 exit_code, CommonTypes.BigInt memory result) = PowerAPI.networkRawPower(); Errors.revertOnError(exit_code); return result; } function miner_raw_power(uint64 minerID) public view returns (PowerTypes.MinerRawPowerReturn memory) { (int256 exit_code, PowerTypes.MinerRawPowerReturn memory result) = PowerAPI.minerRawPower(minerID); Errors.revertOnError(exit_code); return result; } } ``` ### Call the verified registry actor The following example imports the verified registry actor library and creates a callable method for each of the [available actor methods](#call-the-verified-registry-actor). For the full code, see [the GitHub repository](https://github.com/filecoin-project/filecoin-solidity/blob/master/contracts/v0.8/tests/verifreg.test.sol). ```solidity pragma solidity ^0.8.18; import "../types/VerifRegTypes.sol"; import "../types/CommonTypes.sol"; import "../VerifRegAPI.sol"; import "../utils/Errors.sol"; contract VerifRegApiTest { function get_claims(VerifRegTypes.GetClaimsParams memory params) public view returns (VerifRegTypes.GetClaimsReturn memory) { (int256 exit_code, VerifRegTypes.GetClaimsReturn memory result) = VerifRegAPI.getClaims(params); Errors.revertOnError(exit_code); return result; } function add_verified_client(VerifRegTypes.AddVerifiedClientParams memory params) public { int256 exit_code = VerifRegAPI.addVerifiedClient(params); Errors.revertOnError(exit_code); } function remove_expired_allocations( VerifRegTypes.RemoveExpiredAllocationsParams memory params ) public returns (VerifRegTypes.RemoveExpiredAllocationsReturn memory) { (int256 exit_code, VerifRegTypes.RemoveExpiredAllocationsReturn memory result) = VerifRegAPI.removeExpiredAllocations(params); Errors.revertOnError(exit_code); return result; } function extend_claim_terms(VerifRegTypes.ClaimTerm[] memory claimTerms) public returns (CommonTypes.BatchReturn memory) { (int256 exit_code, CommonTypes.BatchReturn memory result) = VerifRegAPI.extendClaimTerms(claimTerms); Errors.revertOnError(exit_code); return result; } function remove_expired_claims(VerifRegTypes.RemoveExpiredClaimsParams memory params) public returns (VerifRegTypes.RemoveExpiredClaimsReturn memory) { (int256 exit_code, VerifRegTypes.RemoveExpiredClaimsReturn memory result) = VerifRegAPI.removeExpiredClaims(params); Errors.revertOnError(exit_code); return result; } } ``` [Was this page helpful?](https://airtable.com/apppq4inOe4gmSSlk/pagoZHC2i1iqgphgl/form?prefill_Page+URL=https://docs.filecoin.io/reference/built-in-actors/filecoin.sol) # JSON-RPC Find out how to manage and interact with the Filecoin network using the standard JSON-RPC API. ## Quick start The easiest way to test the API is to use Curl commands. A Curl command to the Filecoin network looks something like this: ```curl curl --location --request POST '<NODE_ADDRESS>' \ --header 'Content-Type: application/json' \ --data-raw '{ "jsonrpc":"2.0", "method":"<API_METHOD_TO_CALL>", "params": [<ARRAY OF PARAMETERS>], "id":1 }' ``` ## Step-by-step example 1. In a terminal window, use Curl to request the current chain head from a public [Glif](https://glif.io/en) node.\\ * ```shell curl -X POST 'https://api.node.glif.io/rpc/v1' \ -H 'Content-Type: application/json' \ --data '{"jsonrpc":"2.0","id":1,"method":"Filecoin.ChainHead","params":[]}' ``` ```shell {"jsonrpc":"2.0","result":{"Cids":[{"/":"bafy2bzaceayoigaf3v5muqmknpjfkguse43jp4t2zxhpmykhqynqhkdgpgybc"},{"/":"bafy2bzacecnrtzlhn6h75gm7tozhzuw77plvdhniwzfj7wgmyuju6wn573h22"},{"/":"bafy2bzacecygiaxfsqv7ecb2gvodzh74eret3pchwe5e4j5a3mzlwasvndi6i"},{"/":"bafy2bzacebe477tdmijfse4je2g63gnnkdgzj3ftq6zbygd7toszkrsjts6uu"},{"/":"bafy2bzacedoe6hcxy2cgqzbg4p7qolbd5imbjpjnz2tj4n7o3kw2md4uv2ttq"},{"/":"bafy2bzacec7wbqvskwvolireljmufszdu5nk37yyg4qtxgnrwbyipgoenmhc6"},{"/":"bafy2bzaceahxdiauteywlbjnwj3ntr72qcbamtq3nbvjzyn5wruithpyqyxbm"}],"Blocks":[{"Miner":"f0693008","Ticket":{"VRFProof":"uLR0LHfNBAfQzyYUVBiIEXzyblPv3yPIEsJQGTpaAvO1ZriPZ7wC2IFpw7mrz1RvDQEfsgRXGxb6APTRvrPiFEAe35RFNLKC9SYb64PNcDYwGY4de5LdlHfyUv+Ovwg5"}... ``` The ChainHead endpoint doesn’t require any input parameters, so we’ve left `params` an empty array `[]`. * The above command will output a large chunk of JSON data. You can use [JSON processor JQ](https://stedolan.github.io/jq/) to *prettify* the output: ``` ``` 1. ```shell curl -X POST 'https://api.node.glif.io/rpc/v1' \ -H 'Content-Type: application/json' \ --data '{"jsonrpc":"2.0","id":1,"method":"Filecoin.ChainHead","params":[]}' \ | jq ``` ```json { "jsonrpc": "2.0", "result": { "Cids": [ { "/": "bafy2bzacecrbhy67by4upktab6rvbgd3w5jml7zog4ifoaupo35yo4rbbc4am" }, { "/": "bafy2bzacecm42csr2ysmgpj54lz762iom4n4gcafkerijirzsfzq3jni2gqyu" } ], "Blocks": [ { "Miner": "f0152747", "Ticket": { ... ``` ## Permissions Each method has specific permissions that must be met before you can receive a response from a Filecoin node. Methods with the `read` permission can be called by anyone at anytime, without the need for a token. All other permissions require you to send an authentication along with you request. * `read`: Read node state, no private data. * `write`: Write to local store / chain, and read permissions. * `sign`: Use private keys stored in wallet for signing, read and write permissions. * `admin`: Manage permissions, read, write, and sign permissions. ## Authentication Each node implementation has different ways to generate and manage authentication tokens. Take a look at your node’s specific documentation: * [Lotus](https://lotus.filecoin.io) * [Venus](https://venus.filecoin.io) If you are using a node provider service like [Glif](https://glif.io/en), take a look at your providers documentation to find out how to manage authentication tokens. [Was this page helpful?](https://airtable.com/apppq4inOe4gmSSlk/pagoZHC2i1iqgphgl/form?prefill_Page+URL=https://docs.filecoin.io/reference/json-rpc) # Auth ## AuthNew Perms: admin Inputs: ```json [["write"]] ``` Response: `"Ynl0ZSBhcnJheQ=="` ## AuthVerify Perms: read Inputs: ```json ["string value"] ``` Response: ```json ["write"] ``` [Was this page helpful?](https://airtable.com/apppq4inOe4gmSSlk/pagoZHC2i1iqgphgl/form?prefill_Page+URL=https://docs.filecoin.io/reference/json-rpc/auth) # Chain The Chain method group contains methods for interacting with the blockchain, but that do not require any form of state computation. ## ChainBlockstoreInfo ChainBlockstoreInfo returns some basic information about the blockstore Perms: read Inputs: `null` Response: ```json { "abc": 123 } ``` ## ChainCheckBlockstore ChainCheckBlockstore performs an (asynchronous) health check on the chain/state blockstore if supported by the underlying implementation. Perms: admin Inputs: `null` Response: `{}` ## ChainDeleteObj ChainDeleteObj deletes node referenced by the given CID Perms: admin Inputs: ```json [ { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" } ] ``` Response: `{}` ## ChainExport ChainExport returns a stream of bytes with CAR dump of chain data. The exported chain data includes the header chain from the given tipset back to genesis, the entire genesis state, and the most recent 'nroots' state trees. If oldmsgskip is set, messages from before the requested roots are also not included. Perms: read Inputs: ```json [ 10101, true, [ { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" }, { "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" } ] ] ``` Response: `"Ynl0ZSBhcnJheQ=="` ## ChainExportRangeInternal ChainExportRangeInternal triggers the export of a chain CAR-snapshot directly to disk. It is similar to ChainExport, except, depending on options, the snapshot can include receipts, messages and stateroots for the length between the specified head and tail, thus producing "archival-grade" snapshots that include all the on-chain data. The header chain is included back to genesis and these snapshots can be used to initialize Filecoin nodes. Perms: admin Inputs: ```json [ [ { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" }, { "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" } ], [ { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" }, { "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" } ], { "WriteBufferSize": 123, "NumWorkers": 123, "IncludeMessages": true, "IncludeReceipts": true, "IncludeStateRoots": true } ] ``` Response: `{}` ## ChainGetBlock ChainGetBlock returns the block specified by the given CID. Perms: read Inputs: ```json [ { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" } ] ``` Response: ```json { "Miner": "f01234", "Ticket": { "VRFProof": "Ynl0ZSBhcnJheQ==" }, "ElectionProof": { "WinCount": 9, "VRFProof": "Ynl0ZSBhcnJheQ==" }, "BeaconEntries": [ { "Round": 42, "Data": "Ynl0ZSBhcnJheQ==" } ], "WinPoStProof": [ { "PoStProof": 8, "ProofBytes": "Ynl0ZSBhcnJheQ==" } ], "Parents": [ { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" } ], "ParentWeight": "0", "Height": 10101, "ParentStateRoot": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" }, "ParentMessageReceipts": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" }, "Messages": { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" }, "BLSAggregate": { "Type": 2, "Data": "Ynl0ZSBhcnJheQ==" }, "Timestamp": 42, "BlockSig": { "Type": 2, "Data": "Ynl0ZSBhcnJheQ==" }, "ForkSignaling": 42, "ParentBaseFee": "0" } ``` ## ChainGetBlockMessages ChainGetBlockMessages returns messages stored in the specified block. Note: If there are multiple blocks in a tipset, it's likely that some messages will be duplicated. It's also possible for blocks in a tipset to have different messages from the same sender at the same nonce. When that happens, only the first message (in a block with lowest ticket) will be considered for execution NOTE: THIS METHOD SHOULD ONLY BE USED FOR GETTING MESSAGES IN A SPECIFIC BLOCK DO NOT USE THIS METHOD TO GET MESSAGES INCLUDED IN A TIPSET Use ChainGetParentMessages, which will perform correct message deduplication Perms: read Inputs: ```json [ { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" } ] ``` Response: ```json { "BlsMessages": [ { "Version": 42, "To": "f01234", "From": "f01234", "Nonce": 42, "Value": "0", "GasLimit": 9, "GasFeeCap": "0", "GasPremium": "0", "Method": 1, "Params": "Ynl0ZSBhcnJheQ==", "CID": { "/": "bafy2bzacebbpdegvr3i4cosewthysg5xkxpqfn2wfcz6mv2hmoktwbdxkax4s" } } ], "SecpkMessages": [ {
프로젝트로 돌아가기