hermeznetwork / hermez-go-sdk Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
Have methods for creating transactions:
// Generate L2 txs easy mode (fee and nonce calculated on behalf of the user)
func NewTransferToIdx(from, to, amount) common.PoolL2Tx
func NewTransferToEthAddr(from, to, amount) common.PoolL2Tx
func NewTransferToBJJ(from, to, amount) common.PoolL2Tx
func NewExit(from, to, amount) common.PoolL2Tx
// Generate L2 txs pro mode (fee and nonce set manually by the user)
func NewTransferToIdxAdvanced(from, to, amount, nonce, fee) common.PoolL2Tx
func NewTransferToEthAddrAdvanced(from, to, amount, nonce, fee) common.PoolL2Tx
func NewTransferToBJJAdvanced(from, to, amount, nonce, fee) common.PoolL2Tx
func NewExitAdvanced(from, to, amount, nonce, fee) common.PoolL2Tx
Method for requesting tx:
func RequestTx(tx, requestedTx) error
Method for signing:
func Sign(tx, chainID, privateKey) error
Create an atomic group (set the RqOffset, and AtomicGroupID....):
func NewAtomicGroup(txs) common.AtomicGroup
Note that all this methods are extremly easy to implement except NewAtomicGroup
that it's a bit tricky due to protocol limitations on the RqOffset. Implementing this would result in a cleaner SDK where:
hermez-node
structs as much as possible to avoid confusion with similar structs and easier to maintainRight now there is only one method for getting information on transactions on the pool: transaction.GetTransactionsInPool
. According to the function description: GetTransactionsInPool connects to a hermez node and pull all transactions in the pool
, which is not true because it query the first 1000 txs not all of them. But most importantly, most of the time users will want to query just one tx base on the ID.
Pleae add the method: GetTransactionInPool
that returns a single transaction based on tx ID
Avoid having custom structs just for the sake of marshaling JSONs. Note that this is needed in some cases if the hermez-node
structs don't have the marshalers implemented.
The function AtomicTransfer should receive the txs already signed, as the common case will be for no single entity to have all the related private keys to an atomic group. So this function should take care of:
Of course all of this already happens, just need to change the interface of the function to have as input txs []common.PoolL2Tx.
Additionally, it would be nice to validate that:
This is actually same validations that the hermez-node will run. But I believe running the validations before sending the request may be easier to debug, and can give more info to users.
Keep in mind that the current code is actually working (I believe), so it's up to you to implement this or not, in this PR or in future ones. The only thing I would say it's mandatory is to don't sign the txs in this function, as this will make the SDK unusable
Related to #2 (comment)
In many parts of the code strings are used instead of the actual types, this leads to all sorts of errors and users need to have a deeper understanding of everything. For instance should I send "hez:0x347943..."
or 0x347943...
.
We should take advantage of strong types. We love Go and not JS for many reasons, and this is for sure one of them. JSON formatting should be kept at marshaling level when sending to the API or we could use String()
when logging stuff, but we should avoid as much as possible this in public methods / structs.
In this drafted PR I encountered some problems precisely because of this #11
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.