Skip to content

Commit a17f92c

Browse files
Merge pull request #64 from web3data/feature/stellar
Added stellar support
2 parents cbdb98f + 98e19f4 commit a17f92c

File tree

9 files changed

+1042
-959
lines changed

9 files changed

+1042
-959
lines changed

dist/web3data.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api.md

Lines changed: 946 additions & 946 deletions
Large diffs are not rendered by default.

examples/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
·
8585
·
8686
·
87-
<button onClick="runBlockchain('bch')" id="goBtn">Blockchain Method</button>
87+
<button onClick="runBlockchain('xlm')" id="goBtn">Blockchain Method</button>
8888
</div>
8989
<div id="output">
9090
<p>Results<p>
@@ -108,14 +108,14 @@
108108
console.log('status ->', status.type)
109109
})
110110

111-
web3data.on({eventName: 'block'}, data => {
112-
console.log('block', data)
113-
setResult(data)
114-
})
115-
web3data.on({eventName: 'block', filters: { number: 605859 }}, data => {
116-
console.log('block NUMBER', data)
117-
setResult(data)
118-
})
111+
// web3data.on({eventName: 'block'}, data => {
112+
// console.log('block', data)
113+
// setResult(data)
114+
// })
115+
// web3data.on({eventName: 'block', filters: { number: 26811436 }}, data => {
116+
// console.log('block NUMBER', data)
117+
// setResult(data)
118+
// })
119119
web3data.on({eventName: 'transaction'}, data => {
120120
console.log('transaction', data)
121121
setResult(data)
@@ -140,7 +140,7 @@
140140
}
141141

142142
// run specific blockchain things
143-
const activeBlockchain = 'btc'
143+
const activeBlockchain = 'xlm'
144144
function runBlockchain(namespace) {
145145
namespace = namespace || activeBlockchain
146146
const apiKey = document.querySelector('#apikey-input').value

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web3data-js",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "A javascript wrapper for accessing amberdata's public API.",
55
"main": "index.js",
66
"browser": "dist/web3data.min.js",

src/constants.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports.BLOCKCHAIN_ID_BITCOIN_SV = 'a818635d36dbe125e26167c4438e2217'
1313
module.exports.BLOCKCHAIN_ID_LITECOIN = 'f94be61fd9f4fa684f992ddfd4e92272'
1414
module.exports.BLOCKCHAIN_ID_RIPPLE = '2b8a5d8975e8c2a2ed92450450979a3c'
1515
module.exports.BLOCKCHAIN_ID_ZCASH = 'b7d4f994f33c709be4ce6cbae31d7b8e'
16+
module.exports.BLOCKCHAIN_ID_STELLAR = '822e2ebe02f74df8'
1617

1718
/* Endpoints */
1819
module.exports.ADDRESSES_ENDPOINT = '/addresses'
@@ -106,5 +107,30 @@ module.exports.LTC_METHODS = {
106107
transaction: ['getTransactions', 'getTransaction', 'getPendingTransactions']
107108
}
108109

110+
module.exports.XLM_METHODS = {
111+
address: [
112+
'getAllAddresses',
113+
'getInformation',
114+
'getMetadata',
115+
'getTransactions',
116+
// 'getPendingTransactions',
117+
'getBalance',
118+
'getMetrics'
119+
],
120+
block: [
121+
'getBlocks',
122+
'getBlock',
123+
'getBlockNumber',
124+
'getTransactions',
125+
'getTransactionFromBlock',
126+
'getMetrics'
127+
],
128+
transaction: [
129+
'getTransactions',
130+
'getTransaction'
131+
// 'getPendingTransactions'
132+
]
133+
}
134+
109135
/* HTTP Response codes */
110136
module.exports.HTTP_CODE_NOT_FOUND = 404

src/web3data.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Btc = require('./btc')
1919
const Bch = require('./bch')
2020
const Bsv = require('./bsv')
2121
const Ltc = require('./ltc')
22+
const Xlm = require('./xlm')
2223
const Zec = require('./zec')
2324
const WebSocketClient = require('./websocket')
2425

@@ -128,6 +129,7 @@ class Web3Data extends Web3DataFactory {
128129
this.bch = new Bch(Web3DataFactory, apiKey, options)
129130
this.bsv = new Bsv(Web3DataFactory, apiKey, options)
130131
this.ltc = new Ltc(Web3DataFactory, apiKey, options)
132+
this.xlm = new Xlm(Web3DataFactory, apiKey, options)
131133
this.zec = new Zec(Web3DataFactory, apiKey, options)
132134

133135
this.websocket = null

src/xlm.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const {
2+
BLOCKCHAIN_ID_STELLAR: BLOCKCHAIN_ID,
3+
BTC_METHODS: METHODS
4+
} = require('./constants')
5+
const {methodFactory} = require('./utils')
6+
7+
/**
8+
* Class for all Stellar based methods.
9+
*
10+
* @private
11+
*/
12+
class Xlm {
13+
constructor(Web3data, apiKey, options) {
14+
options.blockchainId = BLOCKCHAIN_ID
15+
this.web3data = new Web3data(apiKey, options)
16+
methodFactory(this, METHODS)
17+
}
18+
19+
/* See Web3Data class for details on rpc method */
20+
rpc(method, params) {
21+
return this.web3data.rpc(method, params)
22+
}
23+
}
24+
25+
module.exports = Xlm

test/xlm.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import test from 'ava'
2+
import {setUpPolly, getNewWeb3DataInstance} from "./utils";
3+
import { XLM_METHODS as METHODS } from "../src/constants";
4+
5+
/***********************************
6+
* -------- Tests Setup ---------- *
7+
**********************************/
8+
test.before(t => {
9+
t.context.polly = setUpPolly('xlm')
10+
})
11+
12+
test.after(async t => {
13+
await t.context.polly.stop()
14+
})
15+
16+
test.beforeEach(t => {
17+
t.context.web3data = getNewWeb3DataInstance()
18+
});
19+
20+
/*********************************
21+
* ----------- Tests ----------- *
22+
*********************************/
23+
24+
test('Check the xlm namespace contains all defined methods', t => {
25+
for(const namespace of Object.keys(METHODS)) {
26+
for (const method of METHODS[namespace]) {
27+
t.truthy(t.context.web3data.xlm[namespace][method])
28+
}
29+
}
30+
})

test/zec.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { BTC_METHODS as METHODS } from "../src/constants";
66
* -------- Tests Setup ---------- *
77
**********************************/
88
test.before(t => {
9-
t.context.polly = setUpPolly('ltc')
9+
t.context.polly = setUpPolly('zec')
1010
})
1111

1212
test.after(async t => {

0 commit comments

Comments
 (0)