diff --git a/dist/lamden.js b/dist/lamden.js index 608b9b6..1cd2c10 100644 --- a/dist/lamden.js +++ b/dist/lamden.js @@ -5562,6 +5562,16 @@ class LamdenMasterNode_API{ } + async getContractVariables(contract){ + let path = `/contracts/${contract}/variables`; + return this.send('GET', path, {}, undefined, (res, err) => { + try{ + if (res.variables) return res + } catch (e){} + return {}; + }) + } + async pingServer(){ return this.send('GET', '/ping', {}, undefined, (res, err) => { try { diff --git a/package.json b/package.json index 200cad7..20e8bc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lamden-js", - "version": "1.3.5", + "version": "1.3.6", "description": "A javascript implementaion for creating wallets, submitting transactions and interacting with masternodes on the Lamden Blockchain.", "main": "dist/lamden.js", "scripts": { diff --git a/src/js/masternode-api.js b/src/js/masternode-api.js index 5adcf49..0769370 100644 --- a/src/js/masternode-api.js +++ b/src/js/masternode-api.js @@ -91,6 +91,16 @@ export class LamdenMasterNode_API{ } + async getContractVariables(contract){ + let path = `/contracts/${contract}/variables` + return this.send('GET', path, {}, undefined, (res, err) => { + try{ + if (res.variables) return res + } catch (e){} + return {}; + }) + } + async pingServer(){ return this.send('GET', '/ping', {}, undefined, (res, err) => { try { diff --git a/test/masternode_api-test.js b/test/masternode_api-test.js index 46e2d5d..b4ffdbf 100644 --- a/test/masternode_api-test.js +++ b/test/masternode_api-test.js @@ -128,6 +128,27 @@ describe('Test Masternode API returns', () => { }) }) + context('Masternode_API.getContractVariables()', () => { + it('returns an array if a contract exists on the blockchain', async () => { + let response = await goodNetwork_api.getContractVariables('currency') + expect(Array.isArray(response.variables)).to.be(true); + expect(Array.isArray(response.hashes)).to.be(true); + expect(response.hashes.length > 0).to.be(true); + }) + it('returns an empty Object if a contract does not exist on the blockchain', async () => { + let response = await goodNetwork_api.getContractVariables(wallet.new_wallet().vk) + expect(Array.isArray(response.variables)).to.be(false); + expect(Array.isArray(response.hashes)).to.be(false); + expect(Object.keys(response).length === 0).to.be(true); + }) + it('returns empty Object if provided network is unresponsive', async () => { + let response = await badNetwork_api.getContractVariables('currency') + expect(Array.isArray(response.variables)).to.be(false); + expect(Array.isArray(response.hashes)).to.be(false); + expect(Object.keys(response).length === 0).to.be(true); + }) + }) + context('Masternode_API.getVariable()', () => { it('returns the value of the variable if the key exists', async () => { let key = balanceCheckWallet.float;