cleanup
This commit is contained in:
parent
ee5d56397c
commit
c53d72cebf
|
@ -154,7 +154,7 @@ class EventSyncer {
|
||||||
}
|
}
|
||||||
|
|
||||||
_parseEventCBFactory = (filterConditions, filterConditionsCb, eventKey) => (err, ev) => {
|
_parseEventCBFactory = (filterConditions, filterConditionsCb, eventKey) => (err, ev) => {
|
||||||
if(err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ class LogSyncer {
|
||||||
sub.subscribe = (next, error, complete) => {
|
sub.subscribe = (next, error, complete) => {
|
||||||
const s = og_subscribe.apply(sub, [next, error, complete]);
|
const s = og_subscribe.apply(sub, [next, error, complete]);
|
||||||
s.add(() => { // Removing web3js subscription when rxJS unsubscribe is executed
|
s.add(() => { // Removing web3js subscription when rxJS unsubscribe is executed
|
||||||
if(eth_subscribe) eth_subscribe.unsubscribe();
|
if (eth_subscribe) eth_subscribe.unsubscribe();
|
||||||
});
|
});
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import LogSyncer from './logSyncer';
|
||||||
export default class Subspace {
|
export default class Subspace {
|
||||||
|
|
||||||
constructor(provider, options = {}) {
|
constructor(provider, options = {}) {
|
||||||
if(provider.constructor.name !== "WebsocketProvider"){
|
if (provider.constructor.name !== "WebsocketProvider") {
|
||||||
console.warn("subspace: it's recommended to use a websocket provider to react to new events");
|
console.warn("subspace: it's recommended to use a websocket provider to react to new events");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ export default class Subspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
clearDB(collection) {
|
clearDB(collection) {
|
||||||
if(collection){
|
if (collection){
|
||||||
// TODO: delete specific collection
|
// TODO: delete specific collection
|
||||||
} else {
|
} else {
|
||||||
// TODO: delete everything
|
// TODO: delete everything
|
||||||
|
@ -63,10 +63,10 @@ export default class Subspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
_initNewBlocksSubscription() {
|
_initNewBlocksSubscription() {
|
||||||
if(this.newBlocksSubscription != null || this.options.callInterval !== 0) return;
|
if (this.newBlocksSubscription != null || this.options.callInterval !== 0) return;
|
||||||
|
|
||||||
this.newBlocksSubscription = this.web3.subscribe('newBlockHeaders', (err, result) => {
|
this.newBlocksSubscription = this.web3.subscribe('newBlockHeaders', (err, result) => {
|
||||||
if(err) {
|
if (err) {
|
||||||
sub.error(err);
|
sub.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ export default class Subspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
_initCallInterval() {
|
_initCallInterval() {
|
||||||
if(this.intervalTracker != null || this.options.callInterval === 0) return;
|
if (this.intervalTracker != null || this.options.callInterval === 0) return;
|
||||||
|
|
||||||
this.intervalTracker = setInterval(() => {
|
this.intervalTracker = setInterval(() => {
|
||||||
this.callables.forEach(fn => {
|
this.callables.forEach(fn => {
|
||||||
|
@ -94,7 +94,7 @@ export default class Subspace {
|
||||||
const method = contractInstance.methods[propName].apply(contractInstance.methods[propName], methodArgs)
|
const method = contractInstance.methods[propName].apply(contractInstance.methods[propName], methodArgs)
|
||||||
const callContractMethod = () => {
|
const callContractMethod = () => {
|
||||||
method.call.apply(method.call, [callArgs, (err, result) => {
|
method.call.apply(method.call, [callArgs, (err, result) => {
|
||||||
if(err) {
|
if (err) {
|
||||||
sub.error(err);
|
sub.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -115,11 +115,11 @@ export default class Subspace {
|
||||||
trackBalance(address, erc20Address) {
|
trackBalance(address, erc20Address) {
|
||||||
const sub = new ReplaySubject();
|
const sub = new ReplaySubject();
|
||||||
|
|
||||||
if(!isAddress(address)) throw "invalid address"
|
if (!isAddress(address)) throw "invalid address"
|
||||||
if(erc20Address && !isAddress(erc20Address)) throw "invalid ERC20 contract address"
|
if (erc20Address && !isAddress(erc20Address)) throw "invalid ERC20 contract address"
|
||||||
|
|
||||||
let callFn;
|
let callFn;
|
||||||
if(!erc20Address){
|
if (!erc20Address){
|
||||||
callFn = () => {
|
callFn = () => {
|
||||||
const fn = this.web3.getBalance;
|
const fn = this.web3.getBalance;
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ export default class Subspace {
|
||||||
// balanceOf
|
// balanceOf
|
||||||
const data = "0x70a08231" + "000000000000000000000000" + stripHexPrefix(erc20Address);
|
const data = "0x70a08231" + "000000000000000000000000" + stripHexPrefix(erc20Address);
|
||||||
fn.apply(fn, [{to: erc20Address, data}, (err, result) => {
|
fn.apply(fn, [{to: erc20Address, data}, (err, result) => {
|
||||||
if(err) {
|
if (err) {
|
||||||
sub.error(err);
|
sub.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ export default class Subspace {
|
||||||
|
|
||||||
close(){
|
close(){
|
||||||
clearInterval(this.intervalTracker);
|
clearInterval(this.intervalTracker);
|
||||||
if(this.newBlocksSubscription) this.newBlocksSubscription.unsubscribe();
|
if (this.newBlocksSubscription) this.newBlocksSubscription.unsubscribe();
|
||||||
this.eventSyncer.close();
|
this.eventSyncer.close();
|
||||||
this.intervalTracker = null;
|
this.intervalTracker = null;
|
||||||
this.callables = [];
|
this.callables = [];
|
||||||
|
|
Loading…
Reference in New Issue