@pioneer-platform/avax-network 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +151 -92
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -70,21 +70,18 @@ var PROVIDER;
|
|
|
70
70
|
var NODE_URL;
|
|
71
71
|
//TODO precision module
|
|
72
72
|
var BASE = 1000000000000000000;
|
|
73
|
-
/* import moralis */
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if
|
|
83
|
-
|
|
84
|
-
if
|
|
85
|
-
throw Error("Missing MORALIS_MASTER_KEY");
|
|
86
|
-
if (!moralisSecret)
|
|
87
|
-
throw Error("Missing MORALIS_SECRET");
|
|
73
|
+
// /* import moralis */
|
|
74
|
+
// const Moralis = require("moralis-v1/node");
|
|
75
|
+
//
|
|
76
|
+
// /* Moralis init code */
|
|
77
|
+
// const serverUrl = process.env['MORALIS_SERVER_URL'];
|
|
78
|
+
// const appId = process.env['MORALIS_APP_ID'];
|
|
79
|
+
// const masterKey = process.env['MORALIS_MASTER_KEY'];
|
|
80
|
+
// const moralisSecret = process.env['MORALIS_SECRET'];
|
|
81
|
+
// if(!serverUrl) throw Error("Missing MORALIS_SERVER_URL")
|
|
82
|
+
// if(!appId) throw Error("Missing MORALIS_APP_ID")
|
|
83
|
+
// if(!masterKey) throw Error("Missing MORALIS_MASTER_KEY")
|
|
84
|
+
// if(!moralisSecret) throw Error("Missing MORALIS_SECRET")
|
|
88
85
|
//TODO move thorchain/eth stuff to its own module?
|
|
89
86
|
// @ts-ignore
|
|
90
87
|
global.window = { ethereum: {} };
|
|
@@ -92,15 +89,13 @@ module.exports = {
|
|
|
92
89
|
init: function (settings) {
|
|
93
90
|
return __awaiter(this, void 0, void 0, function () {
|
|
94
91
|
return __generator(this, function (_a) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return [2 /*return*/];
|
|
103
|
-
}
|
|
92
|
+
// Enable web3 and get the initialized web3 instance from Web3.js
|
|
93
|
+
//await Moralis.start({ serverUrl, appId, masterKey, moralisSecret });
|
|
94
|
+
//blockbook.init()
|
|
95
|
+
//log.debug("node: ",process.env['PARITY_ARCHIVE_NODE'])
|
|
96
|
+
//use default
|
|
97
|
+
web3 = new Web3(process.env['AVAX_URL']);
|
|
98
|
+
return [2 /*return*/];
|
|
104
99
|
});
|
|
105
100
|
});
|
|
106
101
|
},
|
|
@@ -825,35 +820,43 @@ module.exports = {
|
|
|
825
820
|
// }
|
|
826
821
|
// }
|
|
827
822
|
//
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
823
|
+
// const get_balance = async function(address:string){
|
|
824
|
+
// let tag = TAG + " | get_balance | "
|
|
825
|
+
// try{
|
|
826
|
+
// let output:any = {}
|
|
827
|
+
//
|
|
828
|
+
// // get BSC native balance for a given address
|
|
829
|
+
// const options = {
|
|
830
|
+
// chain: "avalanche",
|
|
831
|
+
// address,
|
|
832
|
+
// // to_block: "1234",
|
|
833
|
+
// };
|
|
834
|
+
// const balance = await Moralis.Web3API.account.getNativeBalance(options);
|
|
835
|
+
// log.info(tag,"balance: ",balance)
|
|
836
|
+
// return balance.balance / 1000000000000000000
|
|
837
|
+
// }catch(e){
|
|
838
|
+
// console.error(tag,e)
|
|
839
|
+
// }
|
|
840
|
+
// }
|
|
841
|
+
//moralis
|
|
842
|
+
// const get_all_tokens = async function(address:string){
|
|
843
|
+
// let tag = TAG + " | get_all_tokens | "
|
|
844
|
+
// try{
|
|
845
|
+
// let output:any = {}
|
|
846
|
+
//
|
|
847
|
+
// // get BSC native balance for a given address
|
|
848
|
+
// const options = {
|
|
849
|
+
// chain: "avalanche",
|
|
850
|
+
// address,
|
|
851
|
+
// // to_block: "1234",
|
|
852
|
+
// };
|
|
853
|
+
// const balance = await Moralis.Web3API.token.getAllTokenIds(options);
|
|
854
|
+
// log.info(tag,"balance: ",balance)
|
|
855
|
+
// return balance.balance / 1000000000000000000
|
|
856
|
+
// }catch(e){
|
|
857
|
+
// console.error(tag,e)
|
|
858
|
+
// }
|
|
859
|
+
// }
|
|
857
860
|
// const get_transactions = async function(address:string,options:any){
|
|
858
861
|
// let tag = TAG + " | get_transactions | "
|
|
859
862
|
// try{
|
|
@@ -885,20 +888,20 @@ var get_balance = function (address) {
|
|
|
885
888
|
// }
|
|
886
889
|
var check_online_status = function () {
|
|
887
890
|
return __awaiter(this, void 0, void 0, function () {
|
|
888
|
-
var tag, output,
|
|
889
|
-
return __generator(this, function (
|
|
890
|
-
switch (
|
|
891
|
+
var tag, output, _a, _b, _c, networkName, _d, e_1;
|
|
892
|
+
return __generator(this, function (_e) {
|
|
893
|
+
switch (_e.label) {
|
|
891
894
|
case 0:
|
|
892
895
|
tag = TAG + " | check_online_status | ";
|
|
893
|
-
|
|
896
|
+
_e.label = 1;
|
|
894
897
|
case 1:
|
|
895
|
-
|
|
898
|
+
_e.trys.push([1, 6, , 7]);
|
|
896
899
|
output = {};
|
|
897
|
-
options = { chain: "bsc", block_number_or_hash: "2" };
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
transactions =
|
|
901
|
-
log.info(transactions)
|
|
900
|
+
// const options = { chain: "bsc", block_number_or_hash: "2" };
|
|
901
|
+
//
|
|
902
|
+
// // get block content on BSC
|
|
903
|
+
// const transactions = await Moralis.Web3API.native.getBlock(options);
|
|
904
|
+
// log.info(transactions)
|
|
902
905
|
// const web3API = async () => {
|
|
903
906
|
// await Moralis.start({ serverUrl, appId, moralisSecret });
|
|
904
907
|
//
|
|
@@ -911,43 +914,99 @@ var check_online_status = function () {
|
|
|
911
914
|
//
|
|
912
915
|
// web3API();
|
|
913
916
|
//isTestnet
|
|
914
|
-
|
|
917
|
+
_a = output;
|
|
918
|
+
return [4 /*yield*/, web3.eth.getNodeInfo()];
|
|
919
|
+
case 2:
|
|
920
|
+
// const options = { chain: "bsc", block_number_or_hash: "2" };
|
|
915
921
|
//
|
|
916
|
-
//
|
|
922
|
+
// // get block content on BSC
|
|
923
|
+
// const transactions = await Moralis.Web3API.native.getBlock(options);
|
|
924
|
+
// log.info(transactions)
|
|
925
|
+
// const web3API = async () => {
|
|
926
|
+
// await Moralis.start({ serverUrl, appId, moralisSecret });
|
|
917
927
|
//
|
|
918
|
-
//
|
|
928
|
+
// const price = await Moralis.Web3API.token.getTokenPrice({
|
|
929
|
+
// address: "0x33b35c665496bA8E71B22373843376740401F106",
|
|
930
|
+
// chain: "avax",
|
|
931
|
+
// });
|
|
932
|
+
// console.log(price);
|
|
933
|
+
// };
|
|
919
934
|
//
|
|
920
|
-
//
|
|
921
|
-
//
|
|
935
|
+
// web3API();
|
|
936
|
+
//isTestnet
|
|
937
|
+
_a.version = _e.sent();
|
|
938
|
+
_b = output;
|
|
939
|
+
return [4 /*yield*/, web3.eth.getChainId()];
|
|
940
|
+
case 3:
|
|
941
|
+
_b.chainId = _e.sent();
|
|
942
|
+
_c = output;
|
|
943
|
+
return [4 /*yield*/, web3.eth.getBlockNumber()
|
|
944
|
+
//TODO get peer count
|
|
945
|
+
// output.peers = await web3.eth.net.getPeerCount()
|
|
946
|
+
];
|
|
947
|
+
case 4:
|
|
948
|
+
_c.height = _e.sent();
|
|
949
|
+
networkName = void 0;
|
|
950
|
+
switch (output.chainId.toString()) {
|
|
951
|
+
case "1":
|
|
952
|
+
networkName = "Main";
|
|
953
|
+
break;
|
|
954
|
+
case "2":
|
|
955
|
+
networkName = "Morden";
|
|
956
|
+
break;
|
|
957
|
+
case "3":
|
|
958
|
+
networkName = "Ropsten";
|
|
959
|
+
break;
|
|
960
|
+
case "4":
|
|
961
|
+
networkName = "Rinkeby";
|
|
962
|
+
break;
|
|
963
|
+
case "42":
|
|
964
|
+
networkName = "Kovan";
|
|
965
|
+
break;
|
|
966
|
+
case "43114":
|
|
967
|
+
networkName = "avalanche";
|
|
968
|
+
break;
|
|
969
|
+
default:
|
|
970
|
+
networkName = "Unknown";
|
|
971
|
+
}
|
|
972
|
+
output.networkName = networkName;
|
|
922
973
|
//
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
// networkName = "Morden";
|
|
930
|
-
// break;
|
|
931
|
-
// case "3":
|
|
932
|
-
// networkName = "Ropsten";
|
|
933
|
-
// break;
|
|
934
|
-
// case "4":
|
|
935
|
-
// networkName = "Rinkeby";
|
|
936
|
-
// break;
|
|
937
|
-
// case "42":
|
|
938
|
-
// networkName = "Kovan";
|
|
939
|
-
// break;
|
|
940
|
-
// default:
|
|
941
|
-
// networkName = "Unknown";
|
|
942
|
-
// }
|
|
943
|
-
// output.networkName = networkName
|
|
974
|
+
_d = output;
|
|
975
|
+
return [4 /*yield*/, web3.eth.getGasPrice()
|
|
976
|
+
//
|
|
977
|
+
// output.syncing = await web3.eth.isSyncing()
|
|
978
|
+
];
|
|
979
|
+
case 5:
|
|
944
980
|
//
|
|
945
|
-
|
|
946
|
-
// output.gasPrice = await web3.eth.getGasPrice()
|
|
981
|
+
_d.gasPrice = _e.sent();
|
|
947
982
|
//
|
|
948
|
-
// //
|
|
949
983
|
// output.syncing = await web3.eth.isSyncing()
|
|
950
984
|
return [2 /*return*/, output];
|
|
985
|
+
case 6:
|
|
986
|
+
e_1 = _e.sent();
|
|
987
|
+
console.error(tag, e_1);
|
|
988
|
+
return [3 /*break*/, 7];
|
|
989
|
+
case 7: return [2 /*return*/];
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
});
|
|
993
|
+
};
|
|
994
|
+
var get_balance = function (address) {
|
|
995
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
996
|
+
var tag, output, e_2;
|
|
997
|
+
return __generator(this, function (_a) {
|
|
998
|
+
switch (_a.label) {
|
|
999
|
+
case 0:
|
|
1000
|
+
tag = TAG + " | get_balance | ";
|
|
1001
|
+
_a.label = 1;
|
|
1002
|
+
case 1:
|
|
1003
|
+
_a.trys.push([1, 3, , 4]);
|
|
1004
|
+
output = {};
|
|
1005
|
+
return [4 /*yield*/, web3.eth.getBalance(address)];
|
|
1006
|
+
case 2:
|
|
1007
|
+
//normal tx info
|
|
1008
|
+
output = (_a.sent()) / BASE;
|
|
1009
|
+
return [2 /*return*/, output];
|
|
951
1010
|
case 3:
|
|
952
1011
|
e_2 = _a.sent();
|
|
953
1012
|
console.error(tag, e_2);
|