-
Notifications
You must be signed in to change notification settings - Fork 7
Update/api extensions 01 #481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
raegartargarian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments about selectors and tests. Also CI/CD fails, it should be fixed before merge. Also on my opinion it good to have all functionality tested manually in gocore console/API before merging to master and creating a new release, because unit tests cannot cover and check all the stuff
Implements the `xcb_synced` API method, providing information about the node's sync status and a subscription for real-time updates. This allows clients to monitor the progress of blockchain synchronization.
Introduces a new smart contract API (scapi) to retrieve token symbols, including a subscription mechanism for real-time updates. Adds `sc_symbol` RPC method to retrieve token symbols from contracts, handling different symbol function selectors and string encodings. Also provides a `symbol` subscription for real-time updates on symbol changes. Implements dynamic string decoding to handle responses from contract calls.
Adds functionality to retrieve the name of a token contract via the `name()` function. It attempts multiple function selectors to accommodate variations in contract implementations. Also includes subscription functionality for real-time name updates. Includes tests to ensure the dynamic string decoding works correctly with name examples.
Adds support for fetching the symbol, name, and balance of CBC20 tokens. Updates the smart contract API to use CBC20 function selectors for symbol and name retrieval, and adds a new BalanceOf method to retrieve token balances. Also includes unit tests to verify the correctness of the BalanceOf implementation.
Implements a new API method to retrieve the number of decimal places used by a given CBC20 token contract. This information is crucial for displaying token amounts correctly and performing accurate calculations. Includes unit tests to ensure correct function data construction and response decoding.
Implements the `TotalSupply` method in the smart contract API to retrieve the total supply of a given token contract. Includes corresponding client-side implementation and unit tests for data construction and response decoding.
Adds a new `sc_length` method to the SmartContract API, which allows retrieving the size of a contract's code in bytes. This method fetches the contract code using `xcb.getCode` and returns the code's byte size, addressing the need to determine the size of deployed contracts. It handles cases where the address is an EOA or the contract has empty code, returning 0 in those scenarios. Includes a comprehensive test suite to validate the function's logic, particularly focusing on the JavaScript example provided by the user and ensuring accurate parsing.
Implements functionality to retrieve key-value metadata from smart contracts adhering to the CIP-150 standard. This includes a new `GetKV` method that retrieves metadata, along with supporting functions to check key existence and sealed status. A corresponding data structure to hold the results is also added. The client is updated to support the new sc_getKV method. A comprehensive set of tests are added to verify correct behaviour, including mock contract interactions and tests for sealed/unsealed keys.
Adds the `ListKV` method to the Smart Contract API, enabling retrieval of keys and values from contracts implementing the CIP-150 standard. This method supports fetching all keys with their associated values and sealed status, or filtering for only sealed keys. It includes function selectors and decoding logic for handling dynamic arrays of strings as required by CIP-150. Also adds tests to verify basic functionality and validate function selectors.
Implements the `TokenURI` method to retrieve the token URI for a given NFT token ID from a CoreNFT contract, adhering to the CIP-721 standard. This allows applications to fetch metadata associated with specific NFTs. Includes unit tests to verify the functionality and correctness of the `TokenURI` method, including function selector validation, data construction, and interaction with a mock contract.
Adds subscription methods for various smart contract events, including balance changes, decimal updates, total supply, code length, key-value metadata, and token URIs. These subscriptions allow clients to receive real-time updates on specific smart contract properties. The initial implementation provides a basic monitoring loop and may require further refinement for production use.
Adds a new `xcb_composeTransaction` RPC method, allowing users to compose transactions with automatic nonce, energy, and energy price estimation. If `sign=true`, the transaction is signed and submitted. Otherwise, it returns the transaction data for external signing. Also includes the `sc` module to the default HTTP and WS modules. Adds tests to verify the structure of the new arguments and results structs.
Adds `GetPrice` and `GetPriceSubscription` methods to the Smart Contract API, enabling retrieval and subscription to price updates from PriceFeed contracts according to CIP-104. This allows clients to access real-time price data from on-chain sources. The `GetPriceSubscription` uses a ticker to periodically check for price changes and notifies subscribers if the price has changed by more than 1%.
Implements a method to check token expiration status based on the CIP-151 Token Lifecycle Metadata Standard. This includes fetching tokenExpiration and tradingStop metadata, comparing the expiration timestamp with the current block timestamp, and providing real-time updates via a subscription.
Implements KYC verification functionality using CorePass KYC smart contracts. This includes: - Adding `GetKYC` and `GetKYCSubscription` methods to check user KYC status - Defining `KYCResult` struct to represent verification results - Implementing a subscription mechanism for real-time KYC status updates. The implementation uses the standard "KYC" field within CorePass contracts for verification, ensuring compatibility with the Core Blockchain system.
## What ❔ Changed known functions selectors to be hashed by NIST SHA3 which is used in Core Blockchain ## Why ❔ Need to have compatibility with hashing system
Corrects the dynamic string decoding logic to handle both null-terminated and length-prefixed strings correctly. The previous implementation had issues with strings of bytes32 type, and also did not correctly return the string data for cases where the data was present with an offset and length. This change ensures accurate and reliable string retrieval from smart contracts.
102627d to
3c36857
Compare
Improves the smart contract API by adding security enhancements, optimizations, and support for retrieving data from smart contracts. This includes: - Centralizing view call message creation for consistency. - Adding response size limits to prevent DoS attacks. - Validating offset and length values to prevent integer overflows. - Returning `hexutil.Big` instead of `big.Int` for consistency with other core blockchain API functions.
Updates `EstimateEnergy` to use the latest block for estimation. Enhances `ComposeTransaction` to return a more structured transaction result, including only meaningful transaction fields. It also now includes the network ID in the transaction response.
Updates the `Decimals` and `Length` functions to return contract values as `hexutil.Big` instead of `uint8` and `uint64` respectively. This change ensures consistency in how contract values are handled and provides better compatibility with other parts of the system that expect `hexutil.Big` values.
… fallback; include network_id in compose
Updates the smart contract API to use the term "ticker" instead of "symbol" for retrieving the token ticker symbol. This change ensures consistency with common terminology and improves clarity in the API. It also updates related subscription methods.
Implement comprehensive smart contract API namespace and enhance transaction composition
New Features Added
1. Smart Contract Namespace (
sc)sc.symbol(),sc.name(),sc.balanceOf(),sc.decimals(),sc.totalSupply()sc.getKV(),sc.listKV()with sealed/unsealed data supportsc.tokenURI()for token metadatasc.getPrice()for latest/aggregated price datasc.expired()for expiration statussc.getKYC()for verification statussc.length()for code size retrieval2. Enhanced Transaction Composition
xcb.composeTransaction(): Automatic nonce, energy, and energy price estimationsignparameter3. WebSocket Subscription Support
scnamespace functions4. Synchronization Enhancements
xcb.synced: New function returning blocks remaining to sync (or 0 if synced)Technical Improvements
API Infrastructure
xcb/backend.goandles/api_backend.goscclient/scclient.goandxcbclient/xcbclient.goCLI Configuration
scto--rpcapi,--wsapi, and--ipcapiflagsDocumentation & Testing
README.mdandSECURITY.mdStandards Compliance
Files Modified/Added
internal/scapi/api.go- New smart contract API serverscclient/scclient.go- Smart contract client APIinternal/xcbapi/api.go- Enhanced transaction compositionxcbclient/xcbclient.go- Transaction composition clientcmd/gocore/flags.go- CLI flag updatesREADME.md&SECURITY.md- Documentation improvementsCore Blockchain JSON-RPC.postman_collection.json- Complete API documentationBenefits
All tests pass ✅, builds succeed ✅, and the API is ready for production use.