Giter Club home page Giter Club logo

lisk-elements's People

Contributors

alejandronanez avatar alepop avatar fchavant avatar fix avatar francoilol avatar hendrikhofstadt avatar ishantiw avatar karmacoma avatar kilkelly avatar nazgolze avatar reyraa avatar senikk avatar shuse2 avatar slaweet avatar tobiaslins avatar toschdev avatar tschakki avatar willclarktech avatar yatki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lisk-elements's Issues

lisk.api().listPeers() should have a format that allows more than peer name

Now it returns:

{  
    "official":[  
        "node01.lisk.io",
        "node02.lisk.io",
        "node03.lisk.io",
        "node04.lisk.io",
        "node05.lisk.io",
        "node06.lisk.io",
        "node07.lisk.io",
        "node08.lisk.io"
    ],
    "ssl":[  
        "login.lisk.io"
    ],
    "testnet":[  
        "83.136.249.129"
    ],
    "localhost":[  
        "localhost"
    ]
}

It should return:

{  
    "official":[  
        {"node" : "node01.lisk.io"},
        {"node" : "node02.lisk.io"},
        {"node" : "node03.lisk.io"},
        {"node" : "node04.lisk.io"},
        {"node" : "node05.lisk.io"},
        {"node" : "node06.lisk.io"},
        {"node" : "node07.lisk.io"},
        {"node" : "node08.lisk.io"}
    ],
    "ssl":[  
        {"node" : "login.lisk.io"}
    ],
    "testnet":[  
        {"node" : "83.136.249.129"}
    ],
    "localhost":[  
        {"node" : "localhost"}
    ]
}

in order to be able to specify other stuff for each peer, e.g. port, ssl.

Add API wrapper module

We should extend lisk-js to support much easier interaction with the lisk API. This would enable lisk-js to be used as a framework independent library in all our client interfaces.

To begin with, we should support the listing of collections, retrieval of single records and posting of all locally signed transactions to internally selected peers.

It should be made possible for the selected peer to be automatically negotiated, or manually selected by the developer.

lisk.api().sendRequest() should check validity of its params

Expected behaviour

Uncaught Invalid parameter value: 'limit'
In browser console it should throw and error saying something like:

> lisk.api().sendRequest('delegates/', {limit:undefined})
TypeError: sendRequest was called Invalid value 'undefined' of parameter 'limit'

Actual behaviour

In browser console:

> lisk.api().sendRequest('delegates/', {limit:undefined})
liskApi.js?e8ff:293 Uncaught TypeError: this.trimObj is not a function
    at eval (eval at <anonymous> (http://localhost:8080/app.js:4799:2), <anonymous>:293:130)
    at Array.reduce (native)
    at LiskAPI.trimObj (eval at <anonymous> (http://localhost:8080/app.js:4799:2), <anonymous>:292:26)
    at LiskAPI.serialiseHttpData (eval at <anonymous> (http://localhost:8080/app.js:4799:2), <anonymous>:282:20)
    at LiskAPI.changeRequest (eval at <anonymous> (http://localhost:8080/app.js:4799:2), <anonymous>:247:59)
    at LiskAPI.sendRequestPromise (eval at <anonymous> (http://localhost:8080/app.js:4799:2), <anonymous>:214:28)
    at LiskAPI.sendRequest (eval at <anonymous> (http://localhost:8080/app.js:4799:2), <anonymous>:189:14)
    at <anonymous>:1:12

It makes it difficult to figure out what actually went wrong if there are more calls and more parameters.

lisk.api().sendRequest() hides errors in callback

Expected behaviour

In browser js console:

> lisk.api().sendRequest('delegates/', {limit:'10'}, (data) =>{console.log(data.ddd.sss)})
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
VM41213:1 TypeError: Cannot read property 'sss' of undefined
    at lisk.api.sendRequest (<anonymous>:1:86)
    at eval (eval at <anonymous> (app.js:4799), <anonymous>:195:11)
> lisk.api().sendRequest('delegates/', {limit:'10'}, (data) =>{try{console.log(data.ddd.sss)} catch(e) {console.log(e)}})
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
VM41213:1 TypeError: Cannot read property 'sss' of undefined
    at lisk.api.sendRequest (<anonymous>:1:86)
    at eval (eval at <anonymous> (app.js:4799), <anonymous>:195:11)

Actual behaviour

In browser js console:

> lisk.api().sendRequest('delegates/', {limit:'10'}, (data) =>{console.log(data.ddd.sss)})
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
> lisk.api().sendRequest('delegates/', {limit:'10'}, (data) =>{try{console.log(data.ddd.sss)} catch(e) {console.log(e)}})
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
VM41213:1 TypeError: Cannot read property 'sss' of undefined
    at lisk.api.sendRequest (<anonymous>:1:86)
    at eval (eval at <anonymous> (app.js:4799), <anonymous>:195:11)

Implement missing features for Lisk Nano

  • add limit parameter to lisk.api().listTransactions(address, callback);
  • create a new api method lisk.api().listPeers(); that returns list of peers for the peer dropdown. It actually contains 3 lists: official, testnet, localhost.
  • provide an API that periodically checks if the active peer is online and calls a callback if peer becomes offline and/or tries to connect to another peer and informs about that in the callback. It could be something like lisk.api().keepOnline(callback);.
  • create a new api method lisk.api().getAccount(address); that calls /api/accounts
  • get rid of object wrappers like { transaction }
  • create a new api method lisk.api().sendTransaction(address, amount, passphrase, secondPassphrase); that creates and sends transaction
  • add orderBy = 'timestamp:desc' parameter to lisk.api().listTransactions()

More on the proposed lisk.api().keepOnline(callback);:
Right now Lisk Nano is using /api/loader/status/ call for this, but it also calls two other requests with the same frequency (every ~10 seconds): /api/accounts and /api/transactions. So lisk-js can be smarter and avoid the /api/loader/status call if there was some other successful call recently. In addition, the /api/transactions call could be cached and the cache purged only if balance or unconfirmedBalance in /api/accounts changed, provided that /api/accounts is called periodically.

Tests should mock http requests

See bellow the output of the "API" part of tests, esp. the last 12 tests show how long each took. Altogether the test suit takes 8 seconds when on pretty good internet connection. If I skip API tests (there is 45 of them), then the rest 228 tests take less than 2 seconds.

There are some nice tools to do the mocking:
http://stackoverflow.com/questions/8021956/node-js-mock-http-request-and-response

    api
      Lisk.api()
        lisk.api()
          ✓ should create a new instance when using lisk.api()
          ✓ new lisk.api() should be Object
        #listPeers
          ✓ should give a set of the peers
        .currentPeer
          ✓ currentPeer should be set by default
        #getNethash
          ✓ Nethash should be hardcoded variables
          ✓ should give corret Nethash for testnet
        #setTestnet
          ✓ should set to testnet
        #setNode
          ✓ should be able to set my own node
          ✓ should select a node when not explicitly set
        #selectNode
          ✓ should return the node from initial settings when set
        #getRandomPeer
          ✓ should give a random peer
        #banNode
          ✓ should add current node to LSK.bannedPeers
        #getFullUrl
          ✓ should give the full url inclusive port
          ✓ should give the full url without port and with SSL
        #getURLPrefix
          ✓ should be http when ssl is false
          ✓ should be https when ssl is true
        #trimObj
          ✓ should not be equal before trim
          ✓ should be equal after trim an Object in keys and value
          ✓ should accept numbers and strings as value
        #toQueryString
          ✓ should create a http string from an object. Like { obj: "myval", key: "myval" } -> obj=myval&key=myval
        #serialiseHttpData
          ✓ should create a http string from an object and trim.
        #getAddressFromSecret
          ✓ should create correct address and publicKey
        #checkRequest
          ✓ should identify GET requests
          ✓ should identify POST requests
          ✓ should identify PUT requests
          ✓ should identify NOACTION requests
        #changeRequest
          ✓ should give the correct parameters for GET requests
          ✓ should give the correct parameters for GET requests with parameters
          ✓ should give the correct parameters for NOACTION requests
          ✓ should give the correct parameters for POST requests
          ✓ should give the correct parameters for PUT requests
        #sendRequest
          ✓ should receive Height from a random public peer (206ms)
        #listActiveDelegates
          ✓ should list active delegates (207ms)
        #listStandyDelegates
          ✓ should list non-active delegates (93ms)
        #searchDelegateByUsername
          ✓ should find a delegate by name (71ms)
        #listBlocks
          ✓ should list amount of blocks defined (81ms)
        #getBlock
          ✓ should get a block of certain height (1275ms)
        #listTransactions
          ✓ should list transactions of a defined account (70ms)
        #getTransaction
          ✓ should list a defined transaction (93ms)
        #listVotes
          ✓ should list votes of an account (144ms)
        #listVoters
          ✓ should list voters of an account (129ms)
        #getAccount
          ✓ should get account information (82ms)
        #sendLSK
          ✓ should send testnet LSK (118ms)

Implement tests for the Browser

Tests are currently all running on Node.
The same tests should also be done in the Browser, to get sure it behaves as expected.

Licensing

Hello guys, I'm a License newbie as @Isabello knows, so I'm probably wrong.

This module is under the GNU General Public License v3.0 and my understanding is that any project using this code should also be under that same license.

http://stackoverflow.com/questions/3902754/mit-vs-gpl-license

Meaning, for example, that exchanges using it (Poloniex, bittrex, ...) should make their code open source if they are using that module.

Is my understanding of the license correct? Please enlighten me

Creating Malformed Transaction

if you use

lisk.transaction.createTransaction(undefined,1000000000,"passphrase","secondpassphrase");

you get a malformed transaction (ie with no recipientId)

Complete multisignature module

Multisignature in the current behaviour is not complete in lisk-js.

Missing:

  • Add signature to multisig transaction
  • Route API requests
  • Test verification of multisignature signatures

Create crypto submodules

Create crypto submodules in order to achieve higher flexibility in regards of maintenance and understanding of the code.

Updating dependencies

Some dependencies are complaining about necessary updates. This shall be done in a PR with dedicated research that nothing breaks.

Rewrite readme

The readme contains description for lisk-js 0.2

Rewrite the readme to cover setup for 0.3 and guide developers and users to the github page documentation.

Improve peer selection

Expected behaviour

If there is a failure to connect to a selected peer, then another peer on the same network should be chosen.

Actual behaviour

If there is a failure to connect to a selected peer, then the current behaviour results in another mainnet peer being selected, regardless of whether a peer on another network was selected.

Steps to reproduce

Select a localhost peer even though there is no instance of Lisk running locally. Perform an API request. Connection will timeout / fail, resulting in a change of peer to one of the predefined mainnet peers. If the intention was to connect to the testnet or a local devnet, the current behaviour would be undesirable.

Possible Solution

Assuming, upon catching an error, the switch is being here: https://github.com/LiskHQ/lisk-js/blob/development/lib/api/liskApi.js#L203.

Then improve information available to selectNode: https://github.com/LiskHQ/lisk-js/blob/development/lib/api/liskApi.js#L143, by allowing the developer to optionally indicate their chosen network using an appropriate nethash.

Then if a nethash is provided, restrict the peer selection to the chosen network. Allowing the switch to occur when matching. Throwing an error when there are no matching peers.

Send LSK doesn't send

The reason is the body is missing from request sent. I will post pull request with fix.

lisk.api().listTransactions(address, callback) send unexpected random param

steps to replicate:

address = '16313739661670634666L'
callback = function (data) { console.log(data);}
lisk.api({node:'localhost', port: 4000}).listTransactions(address, callback);
VM332:1 Object {success: false, error: "Failed to get transactions: Parameter is not supported: random"}
lisk.api().listTransactions(address, callback);
VM332:1 Object {success: false, error: "Failed to get transactions: Parameter is not supported: random"}

API Wrapper async tests

Add asynchronous test for the API wrapper functions, checking if the server answer is as expected

Documentation and Github page

Add documentation updates from 0.2 to 0.3

Including:

documentation of API wrapper
documentation of crypto modules

Wrap it into a github page

API should hide private methods

There are several methods in the lisk-js API that aren't mentioned in the docs, look more like internal utility functions and shouldn't really be used by public, e.g. sendRequestPromise, getRandomPeer, banNode ...

If we expose these methods, people might use them in their projects and then we have to support them else we break other people's projects. On the other hand, if we make them private we can easily refactor and change their behaviour if necessary in the future.

There are several ways to emulate private methods in JavaScrtipt:
http://stackoverflow.com/questions/55611/javascript-private-methods

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.