This repository was archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Merged
PubSub for parity-js #5830
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
66fc121
PubSub Integration WebSocket
kaikun213 f38fb4d
PubSub Provider API
kaikun213 1f6fd73
Parity License and fix switch statement
kaikun213 4df1057
Minor fix: use parameter api
kaikun213 fcffa39
Exclude subscriptionId return
kaikun213 65f8091
Unsubscribe parameters as array
kaikun213 e5ad5b0
secureProvider API added
kaikun213 1f065c5
isSecure check
kaikun213 82134b7
Refractor: Formatting in callback (no Promise)
kaikun213 87ad489
Tests for parityProvider
kaikun213 60d7afd
Refractor: Formatting in callback (secure API)
kaikun213 e2b3759
Updated transaction documentation
kaikun213 6a0b33b
Module instead of API-Names, Options always as array (e.g. empty)
kaikun213 1eb138a
Removed isSecure transport check, because APIs are configurable
kaikun213 de0f0a0
Refractor Provider API to single Pubsub
kaikun213 0476901
Modify transport layer to have single identifier for subscriptions
kaikun213 db5af2e
FIX: Display pubsub errors
kaikun213 95de48c
Discard Messages after unsubscribing
kaikun213 0da4dce
Fix: display error normal messages correctly
kaikun213 0103a7f
Simplified code, removed unnecessary pubsub methods
kaikun213 5a5ad4a
trace_call API 2nd argument blockNumber, first whatTrace
kaikun213 864cf06
Separate namespaces pubsub. eth, parity, net
kaikun213 951d0cc
Keep error for messages from unsubscribed topics.
kaikun213 c9c25ef
Fix: Unsubscribe Promise
kaikun213 a873d56
Add Test: Unsubscribe promise resolved
kaikun213 26d5043
Fix: 'error' in params
kaikun213 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
// Copyright 2015-2017 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Parity is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
import PubsubBase from '../pubsubBase'; | ||
|
||
import { inAddress, inBlockNumber, inHex, inNumber16, inOptions, inFilter } from '../../format/input'; | ||
import { outAddress, outBlock, outNumber, outTransaction, outSyncing, outReceipt, outLog } from '../../format/output'; | ||
|
||
export default class Eth extends PubsubBase { | ||
constructor (transport) { | ||
super(transport); | ||
this._api = 'parity'; | ||
} | ||
|
||
newHeads (callback) { | ||
return this.addListener('eth', 'newHeads', callback); | ||
} | ||
// | ||
// logs (callback) { | ||
// throw Error('not supported yet'); | ||
// } | ||
// | ||
// newPendingTransactions (callback) { | ||
// throw Error('not supported yet'); | ||
// } | ||
// | ||
// syncing (callback) { | ||
// throw Error('not supported yet'); | ||
// } | ||
|
||
// eth API | ||
|
||
protocolVersion (callback) { | ||
return this.addListener(this._api, 'eth_protocolVersion', callback); | ||
} | ||
|
||
syncing (callback) { | ||
return this.addListener(this._api, 'eth_syncing', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outSyncing(data)); | ||
}); | ||
} | ||
|
||
hashrate (callback) { | ||
return this.addListener(this._api, 'eth_hashrate', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}); | ||
} | ||
|
||
coinbase (callback) { | ||
return this.addListener(this._api, 'eth_coinbase', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outAddress(data)); | ||
}); | ||
} | ||
|
||
mining (callback) { | ||
return this.addListener(this._api, 'eth_mining', callback); | ||
} | ||
|
||
gasPrice (callback) { | ||
return this.addListener(this._api, 'eth_gasPrice', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}); | ||
} | ||
|
||
accounts (callback) { | ||
return this.addListener(this._api, 'eth_accounts', (error, accounts) => { | ||
error | ||
? callback(error) | ||
: callback(null, (accounts || []).map(outAddress)); | ||
}); | ||
} | ||
|
||
blockNumber (callback) { | ||
return this.addListener(this._api, 'eth_blockNumber', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}); | ||
} | ||
|
||
getBalance (callback, address, blockNumber = 'latest') { | ||
return this.addListener(this._api, 'eth_getBalance', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}, [inAddress(address), inBlockNumber(blockNumber)]); | ||
} | ||
|
||
getStorageAt (callback, address, index = 0, blockNumber = 'latest') { | ||
return this.addListener(this._api, 'eth_getStorageAt', callback, [inAddress(address), inNumber16(index), inBlockNumber(blockNumber)]); | ||
} | ||
|
||
getBlockByHash (callback, hash, full = false) { | ||
return this.addListener(this._api, 'eth_getBlockByHash', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outBlock(data)); | ||
}, [inHex(hash), full]); | ||
} | ||
|
||
getBlockByNumber (callback, blockNumber = 'latest', full = false) { | ||
return this.addListener(this._api, 'eth_getBlockByNumber', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outBlock(data)); | ||
}, [inBlockNumber(blockNumber), full]); | ||
} | ||
|
||
getTransactionCount (callback, address, blockNumber = 'latest') { | ||
return this.addListener(this._api, 'eth_getTransactionCount', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}, [inAddress(address), inBlockNumber(blockNumber)]); | ||
} | ||
|
||
getBlockTransactionCountByHash (callback, hash) { | ||
return this.addListener(this._api, 'eth_getBlockTransactionCountByHash', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}, [inHex(hash)]); | ||
} | ||
|
||
getBlockTransactionCountByNumber (callback, blockNumber = 'latest') { | ||
return this.addListener(this._api, 'eth_getBlockTransactionCountByNumber', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}, [inBlockNumber(blockNumber)]); | ||
} | ||
|
||
getUncleCountByBlockHash (callback, hash) { | ||
return this.addListener(this._api, 'eth_getUncleCountByBlockHash', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}, [inHex(hash)]); | ||
} | ||
|
||
getUncleCountByBlockNumber (callback, blockNumber = 'latest') { | ||
return this.addListener(this._api, 'eth_getUncleCountByBlockNumber', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}, [inBlockNumber(blockNumber)]); | ||
} | ||
|
||
getCode (callback, address, blockNumber = 'latest') { | ||
return this.addListener(this._api, 'eth_getCode', callback, [inAddress(address), inBlockNumber(blockNumber)]); | ||
} | ||
|
||
call (callback, options, blockNumber = 'latest') { | ||
return this.addListener(this._api, 'eth_call', callback, [inOptions(options), inBlockNumber(blockNumber)]); | ||
} | ||
|
||
estimateGas (callback, options) { | ||
return this.addListener(this._api, 'eth_estimateGas', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}, [inOptions(options)]); | ||
} | ||
|
||
getTransactionByHash (callback, hash) { | ||
return this.addListener(this._api, 'eth_getTransactionByHash', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outTransaction(data)); | ||
}, [inHex(hash)]); | ||
} | ||
|
||
getTransactionByBlockHashAndIndex (callback, hash, index = 0) { | ||
return this.addListener(this._api, 'eth_getTransactionByBlockHashAndIndex', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outTransaction(data)); | ||
}, [inHex(hash), inNumber16(index)]); | ||
} | ||
|
||
getTransactionByBlockNumberAndIndex (callback, blockNumber = 'latest', index = 0) { | ||
return this.addListener(this._api, 'eth_getTransactionByBlockNumberAndIndex', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outTransaction(data)); | ||
}, [inBlockNumber(blockNumber), inNumber16(index)]); | ||
} | ||
|
||
getTransactionReceipt (callback, txhash) { | ||
return this.addListener(this._api, 'eth_getTransactionReceipt', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outReceipt(data)); | ||
}, [inHex(txhash)]); | ||
} | ||
|
||
getUncleByBlockHashAndIndex (callback, hash, index = 0) { | ||
return this.addListener(this._api, 'eth_getUncleByBlockHashAndIndex', callback, [inHex(hash), inNumber16(index)]); | ||
} | ||
|
||
getUncleByBlockNumberAndIndex (callback, blockNumber = 'latest', index = 0) { | ||
return this.addListener(this._api, 'eth_getUncleByBlockNumberAndIndex', callback, [inBlockNumber(blockNumber), inNumber16(index)]); | ||
} | ||
|
||
getLogs (callback, options) { | ||
return this.addListener(this._api, 'eth_getLogs', (error, logs) => { | ||
error | ||
? callback(error) | ||
: callback(null, (logs) => logs.map(outLog)); | ||
}, [inFilter(options)]); | ||
} | ||
|
||
getWork (callback) { | ||
return this.addListener(this._api, 'eth_getWork', callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2015-2017 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Parity is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
export default from './eth'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2015-2017 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Parity is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
export default from './net'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2015-2017 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Parity is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
import PubsubBase from '../pubsubBase'; | ||
|
||
import { outNumber } from '../../format/output'; | ||
|
||
export default class Net extends PubsubBase { | ||
constructor (transport) { | ||
super(transport); | ||
this._api = 'parity'; | ||
} | ||
|
||
// net API | ||
version (callback) { | ||
return this.addListener(this._api, 'net_version', callback); | ||
} | ||
|
||
peerCount (callback) { | ||
return this.addListener(this._api, 'net_peerCount', (error, data) => { | ||
error | ||
? callback(error) | ||
: callback(null, outNumber(data)); | ||
}); | ||
} | ||
|
||
listening (callback) { | ||
return this.addListener(this._api, 'net_listening', callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2015-2017 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Parity is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
export default from './parity'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logs are now available: #5705 but this can come in a separate PR.
Imho we should either uncomment the code or remove it.