@massalabs/wallet-provider 0.0.1-dev.20230522090628 → 0.0.1-dev.20230525084049
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/bundle.js +72 -15
- package/dist/thyra/RequestHandler.d.ts +11 -0
- package/dist/thyra/RequestHandler.js +30 -1
- package/dist/thyra/RequestHandler.js.map +1 -1
- package/dist/thyra/ThyraProvider.d.ts +3 -4
- package/dist/thyra/ThyraProvider.js +43 -13
- package/dist/thyra/ThyraProvider.js.map +1 -1
- package/package.json +1 -1
package/bundle.js
CHANGED
|
@@ -553,7 +553,7 @@ Object.defineProperty(exports, "Provider", { enumerable: true, get: function ()
|
|
|
553
553
|
},{"./AccountDeletion":5,"./AccountImport":6,"./Provider":7}],9:[function(require,module,exports){
|
|
554
554
|
"use strict";
|
|
555
555
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
556
|
-
exports.deleteRequest = exports.postRequest = exports.getRequest = void 0;
|
|
556
|
+
exports.putRequest = exports.deleteRequest = exports.postRequest = exports.getRequest = void 0;
|
|
557
557
|
/**
|
|
558
558
|
* This file defines a TypeScript module with methods for performing GET, POST and DELETE http requests.
|
|
559
559
|
*
|
|
@@ -604,6 +604,7 @@ exports.getRequest = getRequest;
|
|
|
604
604
|
*
|
|
605
605
|
*
|
|
606
606
|
* @param url - The url to call.
|
|
607
|
+
* @param body - The body of the request.
|
|
607
608
|
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
608
609
|
*
|
|
609
610
|
*/
|
|
@@ -653,6 +654,34 @@ async function deleteRequest(url) {
|
|
|
653
654
|
};
|
|
654
655
|
}
|
|
655
656
|
exports.deleteRequest = deleteRequest;
|
|
657
|
+
/**
|
|
658
|
+
* This method makes a PUT request to an http rest point.
|
|
659
|
+
*
|
|
660
|
+
*
|
|
661
|
+
* @param url - The url to call.
|
|
662
|
+
* @param body - The body of the request.
|
|
663
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
664
|
+
*
|
|
665
|
+
*/
|
|
666
|
+
async function putRequest(url, body) {
|
|
667
|
+
let resp = null;
|
|
668
|
+
try {
|
|
669
|
+
resp = await axios_1.default.put(url, body, requestHeaders);
|
|
670
|
+
}
|
|
671
|
+
catch (ex) {
|
|
672
|
+
return {
|
|
673
|
+
isError: true,
|
|
674
|
+
result: null,
|
|
675
|
+
error: new Error('Axios error: ' + String(ex)),
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
isError: false,
|
|
680
|
+
result: resp.data,
|
|
681
|
+
error: null,
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
exports.putRequest = putRequest;
|
|
656
685
|
|
|
657
686
|
},{"axios":14}],10:[function(require,module,exports){
|
|
658
687
|
"use strict";
|
|
@@ -899,18 +928,20 @@ exports.ThyraDiscovery = ThyraDiscovery;
|
|
|
899
928
|
Object.defineProperty(exports, "__esModule", {
|
|
900
929
|
value: true
|
|
901
930
|
});
|
|
902
|
-
exports.ThyraProvider = exports.THYRA_PROVIDER_NAME = exports.
|
|
931
|
+
exports.ThyraProvider = exports.THYRA_PROVIDER_NAME = exports.THYRA_ACCOUNTS_URL = exports.THYRA_URL = exports.THYRA_WALLET_URL = void 0;
|
|
903
932
|
const AccountDeletion_1 = require("../provider/AccountDeletion");
|
|
933
|
+
const AccountImport_1 = require("../provider/AccountImport");
|
|
904
934
|
const RequestHandler_1 = require("./RequestHandler");
|
|
905
935
|
const ThyraAccount_1 = require("./ThyraAccount");
|
|
906
936
|
/**
|
|
907
937
|
* The Thyra accounts url
|
|
908
938
|
*/
|
|
909
|
-
exports.
|
|
939
|
+
exports.THYRA_WALLET_URL = 'https://my.massa/thyra/plugin/massalabs/wallet/rest/wallet/';
|
|
940
|
+
exports.THYRA_URL = 'https://my.massa';
|
|
910
941
|
/**
|
|
911
942
|
* Thyra's url for importing accounts
|
|
912
943
|
*/
|
|
913
|
-
exports.
|
|
944
|
+
exports.THYRA_ACCOUNTS_URL = `${exports.THYRA_WALLET_URL}api/accounts/`;
|
|
914
945
|
/**
|
|
915
946
|
* Thyra's wallet provider name
|
|
916
947
|
*/
|
|
@@ -946,7 +977,7 @@ class ThyraProvider {
|
|
|
946
977
|
async accounts() {
|
|
947
978
|
let thyraAccountsResponse = null;
|
|
948
979
|
try {
|
|
949
|
-
thyraAccountsResponse = await (0, RequestHandler_1.getRequest)(exports.
|
|
980
|
+
thyraAccountsResponse = await (0, RequestHandler_1.getRequest)(exports.THYRA_WALLET_URL);
|
|
950
981
|
} catch (ex) {
|
|
951
982
|
console.error(`Thyra accounts retrieval error`);
|
|
952
983
|
throw ex;
|
|
@@ -964,16 +995,30 @@ class ThyraProvider {
|
|
|
964
995
|
/**
|
|
965
996
|
* This method makes an http call to the Thyra server to import an account with the given publicKey and privateKey.
|
|
966
997
|
*
|
|
967
|
-
* @remarks This method in not yet implemented and depends on `massalabs/thyra-plugin-wallet#82` to be merged first
|
|
968
|
-
*
|
|
969
998
|
* @param publicKey - The public key of the account.
|
|
970
999
|
* @param privateKey - The private key of the account.
|
|
971
1000
|
* @returns a Promise that resolves to an instance of IAccountImportResponse.
|
|
972
1001
|
*
|
|
973
1002
|
*/
|
|
974
1003
|
async importAccount(publicKey, privateKey) {
|
|
975
|
-
|
|
976
|
-
|
|
1004
|
+
const accountImportRequest = {
|
|
1005
|
+
publicKey,
|
|
1006
|
+
privateKey
|
|
1007
|
+
};
|
|
1008
|
+
let thyraAccountsResponse = null;
|
|
1009
|
+
try {
|
|
1010
|
+
thyraAccountsResponse = await (0, RequestHandler_1.putRequest)(exports.THYRA_ACCOUNTS_URL, accountImportRequest);
|
|
1011
|
+
} catch (ex) {
|
|
1012
|
+
console.log(`Thyra accounts retrieval error: ${ex}`);
|
|
1013
|
+
throw ex;
|
|
1014
|
+
}
|
|
1015
|
+
if (thyraAccountsResponse.isError || thyraAccountsResponse.error) {
|
|
1016
|
+
throw thyraAccountsResponse.error.message;
|
|
1017
|
+
}
|
|
1018
|
+
return {
|
|
1019
|
+
response: AccountImport_1.EAccountImportResponse.OK,
|
|
1020
|
+
message: 'Account imported successfully'
|
|
1021
|
+
};
|
|
977
1022
|
}
|
|
978
1023
|
/**
|
|
979
1024
|
* This method sends an http call to the Thyra server to delete the account associated with the given address.
|
|
@@ -987,7 +1032,7 @@ class ThyraProvider {
|
|
|
987
1032
|
try {
|
|
988
1033
|
allAccounts = await (0, RequestHandler_1.getRequest)(exports.THYRA_ACCOUNTS_URL);
|
|
989
1034
|
} catch (ex) {
|
|
990
|
-
console.
|
|
1035
|
+
console.log(`Thyra accounts retrieval error: ${ex}`);
|
|
991
1036
|
throw ex;
|
|
992
1037
|
}
|
|
993
1038
|
if (allAccounts.isError || allAccounts.error) {
|
|
@@ -998,15 +1043,15 @@ class ThyraProvider {
|
|
|
998
1043
|
// delete the account in question
|
|
999
1044
|
let thyraAccountsResponse = null;
|
|
1000
1045
|
try {
|
|
1001
|
-
thyraAccountsResponse = await (0, RequestHandler_1.deleteRequest)(`${exports.THYRA_ACCOUNTS_URL}
|
|
1046
|
+
thyraAccountsResponse = await (0, RequestHandler_1.deleteRequest)(`${exports.THYRA_ACCOUNTS_URL}${accountToDelete.nickname}`);
|
|
1002
1047
|
} catch (ex) {
|
|
1003
|
-
console.
|
|
1048
|
+
console.log(`Thyra accounts deletion error`, ex);
|
|
1004
1049
|
return {
|
|
1005
1050
|
response: AccountDeletion_1.EAccountDeletionResponse.ERROR
|
|
1006
1051
|
};
|
|
1007
1052
|
}
|
|
1008
1053
|
if (thyraAccountsResponse.isError || thyraAccountsResponse.error) {
|
|
1009
|
-
console.
|
|
1054
|
+
console.log(`Thyra accounts deletion error`, thyraAccountsResponse.error.message);
|
|
1010
1055
|
return {
|
|
1011
1056
|
response: AccountDeletion_1.EAccountDeletionResponse.ERROR
|
|
1012
1057
|
};
|
|
@@ -1021,7 +1066,19 @@ class ThyraProvider {
|
|
|
1021
1066
|
* @returns a Promise that resolves to a list of node urls.
|
|
1022
1067
|
*/
|
|
1023
1068
|
async getNodesUrls() {
|
|
1024
|
-
|
|
1069
|
+
let nodesResponse = null;
|
|
1070
|
+
try {
|
|
1071
|
+
nodesResponse = await (0, RequestHandler_1.getRequest)(`${exports.THYRA_URL}/massa/node`);
|
|
1072
|
+
if (nodesResponse.isError || nodesResponse.error) {
|
|
1073
|
+
throw nodesResponse.error.message;
|
|
1074
|
+
}
|
|
1075
|
+
// transform nodesResponse.result to a json and then get the "url" property
|
|
1076
|
+
const nodes = nodesResponse.result;
|
|
1077
|
+
return Array(nodes.url);
|
|
1078
|
+
} catch (ex) {
|
|
1079
|
+
console.error(`Thyra nodes retrieval error`, ex);
|
|
1080
|
+
throw ex;
|
|
1081
|
+
}
|
|
1025
1082
|
}
|
|
1026
1083
|
/**
|
|
1027
1084
|
* This method sends an http call to the Thyra server to create a new random account.
|
|
@@ -1034,7 +1091,7 @@ class ThyraProvider {
|
|
|
1034
1091
|
}
|
|
1035
1092
|
exports.ThyraProvider = ThyraProvider;
|
|
1036
1093
|
|
|
1037
|
-
},{"../provider/AccountDeletion":5,"./RequestHandler":9,"./ThyraAccount":10}],13:[function(require,module,exports){
|
|
1094
|
+
},{"../provider/AccountDeletion":5,"../provider/AccountImport":6,"./RequestHandler":9,"./ThyraAccount":10}],13:[function(require,module,exports){
|
|
1038
1095
|
"use strict";
|
|
1039
1096
|
/**
|
|
1040
1097
|
* This file defines a TypeScript module with various time-related Typescript methods.
|
|
@@ -20,6 +20,7 @@ export declare function getRequest<T>(url: string): Promise<JsonRpcResponseData<
|
|
|
20
20
|
*
|
|
21
21
|
*
|
|
22
22
|
* @param url - The url to call.
|
|
23
|
+
* @param body - The body of the request.
|
|
23
24
|
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
24
25
|
*
|
|
25
26
|
*/
|
|
@@ -33,3 +34,13 @@ export declare function postRequest<T>(url: string, body: object): Promise<JsonR
|
|
|
33
34
|
*
|
|
34
35
|
*/
|
|
35
36
|
export declare function deleteRequest<T>(url: string): Promise<JsonRpcResponseData<T>>;
|
|
37
|
+
/**
|
|
38
|
+
* This method makes a PUT request to an http rest point.
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
* @param url - The url to call.
|
|
42
|
+
* @param body - The body of the request.
|
|
43
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
export declare function putRequest<T>(url: string, body: object): Promise<JsonRpcResponseData<T>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteRequest = exports.postRequest = exports.getRequest = void 0;
|
|
3
|
+
exports.putRequest = exports.deleteRequest = exports.postRequest = exports.getRequest = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* This file defines a TypeScript module with methods for performing GET, POST and DELETE http requests.
|
|
6
6
|
*
|
|
@@ -51,6 +51,7 @@ exports.getRequest = getRequest;
|
|
|
51
51
|
*
|
|
52
52
|
*
|
|
53
53
|
* @param url - The url to call.
|
|
54
|
+
* @param body - The body of the request.
|
|
54
55
|
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
55
56
|
*
|
|
56
57
|
*/
|
|
@@ -100,4 +101,32 @@ async function deleteRequest(url) {
|
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
103
|
exports.deleteRequest = deleteRequest;
|
|
104
|
+
/**
|
|
105
|
+
* This method makes a PUT request to an http rest point.
|
|
106
|
+
*
|
|
107
|
+
*
|
|
108
|
+
* @param url - The url to call.
|
|
109
|
+
* @param body - The body of the request.
|
|
110
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
111
|
+
*
|
|
112
|
+
*/
|
|
113
|
+
async function putRequest(url, body) {
|
|
114
|
+
let resp = null;
|
|
115
|
+
try {
|
|
116
|
+
resp = await axios_1.default.put(url, body, requestHeaders);
|
|
117
|
+
}
|
|
118
|
+
catch (ex) {
|
|
119
|
+
return {
|
|
120
|
+
isError: true,
|
|
121
|
+
result: null,
|
|
122
|
+
error: new Error('Axios error: ' + String(ex)),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
isError: false,
|
|
127
|
+
result: resp.data,
|
|
128
|
+
error: null,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
exports.putRequest = putRequest;
|
|
103
132
|
//# sourceMappingURL=RequestHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestHandler.js","sourceRoot":"","sources":["../../src/thyra/RequestHandler.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,iCAAkE;AAElE,MAAM,cAAc,GAAG;IACrB,MAAM,EACJ,kFAAkF;IACpF,6BAA6B,EAAE,GAAG;IAClC,kCAAkC,EAAE,IAAI;IACxC,8BAA8B,EAAE,mCAAmC;IACnE,cAAc,EAAE,kBAAkB;IAClC,8BAA8B,EAC5B,iDAAiD;CAC7B,CAAC;AAWzB;;;;;;;GAOG;AACI,KAAK,UAAU,UAAU,CAC9B,GAAW;IAEX,IAAI,IAAI,GAAkB,IAAI,CAAC;IAC/B,IAAI;QACF,IAAI,GAAG,MAAM,eAAK,CAAC,GAAG,CAAiC,GAAG,EAAE,cAAc,CAAC,CAAC;KAC7E;IAAC,OAAO,EAAE,EAAE;QACX,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,IAAI,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;SACrB,CAAC;KAC7B;IAED,OAAO;QACL,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,IAAI,CAAC,IAAS;QACtB,KAAK,EAAE,IAAI;KACc,CAAC;AAC9B,CAAC;AAnBD,gCAmBC;AAED
|
|
1
|
+
{"version":3,"file":"RequestHandler.js","sourceRoot":"","sources":["../../src/thyra/RequestHandler.ts"],"names":[],"mappings":";;;A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9B,CAAC;AAxBD,kCAwBC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,aAAa,CACjC,GAAW;IAEX,IAAI,IAAI,GAAkB,IAAI,CAAC;IAC/B,IAAI;QACF,IAAI,GAAG,MAAM,eAAK,CAAC,MAAM,CACvB,GAAG,EACH,cAAc,CACf,CAAC;KACH;IAAC,OAAO,EAAE,EAAE;QACX,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,IAAI,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;SACrB,CAAC;KAC7B;IAED,OAAO;QACL,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,IAAI,CAAC,IAAS;QACtB,KAAK,EAAE,IAAI;KACc,CAAC;AAC9B,CAAC;AAtBD,sCAsBC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,UAAU,CAC9B,GAAW,EACX,IAAY;IAEZ,IAAI,IAAI,GAAkB,IAAI,CAAC;IAC/B,IAAI;QACF,IAAI,GAAG,MAAM,eAAK,CAAC,GAAG,CACpB,GAAG,EACH,IAAI,EACJ,cAAc,CACf,CAAC;KACH;IAAC,OAAO,EAAE,EAAE;QACX,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,IAAI,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;SACrB,CAAC;KAC7B;IAED,OAAO;QACL,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,IAAI,CAAC,IAAS;QACtB,KAAK,EAAE,IAAI;KACc,CAAC;AAC9B,CAAC;AAxBD,gCAwBC"}
|
|
@@ -6,11 +6,12 @@ import { IAccountDetails } from '../account';
|
|
|
6
6
|
/**
|
|
7
7
|
* The Thyra accounts url
|
|
8
8
|
*/
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const THYRA_WALLET_URL = "https://my.massa/thyra/plugin/massalabs/wallet/rest/wallet/";
|
|
10
|
+
export declare const THYRA_URL = "https://my.massa";
|
|
10
11
|
/**
|
|
11
12
|
* Thyra's url for importing accounts
|
|
12
13
|
*/
|
|
13
|
-
export declare const
|
|
14
|
+
export declare const THYRA_ACCOUNTS_URL: string;
|
|
14
15
|
/**
|
|
15
16
|
* Thyra's wallet provider name
|
|
16
17
|
*/
|
|
@@ -57,8 +58,6 @@ export declare class ThyraProvider implements IProvider {
|
|
|
57
58
|
/**
|
|
58
59
|
* This method makes an http call to the Thyra server to import an account with the given publicKey and privateKey.
|
|
59
60
|
*
|
|
60
|
-
* @remarks This method in not yet implemented and depends on `massalabs/thyra-plugin-wallet#82` to be merged first
|
|
61
|
-
*
|
|
62
61
|
* @param publicKey - The public key of the account.
|
|
63
62
|
* @param privateKey - The private key of the account.
|
|
64
63
|
* @returns a Promise that resolves to an instance of IAccountImportResponse.
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ThyraProvider = exports.THYRA_PROVIDER_NAME = exports.
|
|
3
|
+
exports.ThyraProvider = exports.THYRA_PROVIDER_NAME = exports.THYRA_ACCOUNTS_URL = exports.THYRA_URL = exports.THYRA_WALLET_URL = void 0;
|
|
4
4
|
const AccountDeletion_1 = require("../provider/AccountDeletion");
|
|
5
|
+
const AccountImport_1 = require("../provider/AccountImport");
|
|
5
6
|
const RequestHandler_1 = require("./RequestHandler");
|
|
6
7
|
const ThyraAccount_1 = require("./ThyraAccount");
|
|
7
8
|
/**
|
|
8
9
|
* The Thyra accounts url
|
|
9
10
|
*/
|
|
10
|
-
exports.
|
|
11
|
+
exports.THYRA_WALLET_URL = 'https://my.massa/thyra/plugin/massalabs/wallet/rest/wallet/';
|
|
12
|
+
exports.THYRA_URL = 'https://my.massa';
|
|
11
13
|
/**
|
|
12
14
|
* Thyra's url for importing accounts
|
|
13
15
|
*/
|
|
14
|
-
exports.
|
|
16
|
+
exports.THYRA_ACCOUNTS_URL = `${exports.THYRA_WALLET_URL}api/accounts/`;
|
|
15
17
|
/**
|
|
16
18
|
* Thyra's wallet provider name
|
|
17
19
|
*/
|
|
@@ -47,7 +49,7 @@ class ThyraProvider {
|
|
|
47
49
|
async accounts() {
|
|
48
50
|
let thyraAccountsResponse = null;
|
|
49
51
|
try {
|
|
50
|
-
thyraAccountsResponse = await (0, RequestHandler_1.getRequest)(exports.
|
|
52
|
+
thyraAccountsResponse = await (0, RequestHandler_1.getRequest)(exports.THYRA_WALLET_URL);
|
|
51
53
|
}
|
|
52
54
|
catch (ex) {
|
|
53
55
|
console.error(`Thyra accounts retrieval error`);
|
|
@@ -63,16 +65,31 @@ class ThyraProvider {
|
|
|
63
65
|
/**
|
|
64
66
|
* This method makes an http call to the Thyra server to import an account with the given publicKey and privateKey.
|
|
65
67
|
*
|
|
66
|
-
* @remarks This method in not yet implemented and depends on `massalabs/thyra-plugin-wallet#82` to be merged first
|
|
67
|
-
*
|
|
68
68
|
* @param publicKey - The public key of the account.
|
|
69
69
|
* @param privateKey - The private key of the account.
|
|
70
70
|
* @returns a Promise that resolves to an instance of IAccountImportResponse.
|
|
71
71
|
*
|
|
72
72
|
*/
|
|
73
73
|
async importAccount(publicKey, privateKey) {
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
const accountImportRequest = {
|
|
75
|
+
publicKey,
|
|
76
|
+
privateKey,
|
|
77
|
+
};
|
|
78
|
+
let thyraAccountsResponse = null;
|
|
79
|
+
try {
|
|
80
|
+
thyraAccountsResponse = await (0, RequestHandler_1.putRequest)(exports.THYRA_ACCOUNTS_URL, accountImportRequest);
|
|
81
|
+
}
|
|
82
|
+
catch (ex) {
|
|
83
|
+
console.log(`Thyra accounts retrieval error: ${ex}`);
|
|
84
|
+
throw ex;
|
|
85
|
+
}
|
|
86
|
+
if (thyraAccountsResponse.isError || thyraAccountsResponse.error) {
|
|
87
|
+
throw thyraAccountsResponse.error.message;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
response: AccountImport_1.EAccountImportResponse.OK,
|
|
91
|
+
message: 'Account imported successfully',
|
|
92
|
+
};
|
|
76
93
|
}
|
|
77
94
|
/**
|
|
78
95
|
* This method sends an http call to the Thyra server to delete the account associated with the given address.
|
|
@@ -87,7 +104,7 @@ class ThyraProvider {
|
|
|
87
104
|
allAccounts = await (0, RequestHandler_1.getRequest)(exports.THYRA_ACCOUNTS_URL);
|
|
88
105
|
}
|
|
89
106
|
catch (ex) {
|
|
90
|
-
console.
|
|
107
|
+
console.log(`Thyra accounts retrieval error: ${ex}`);
|
|
91
108
|
throw ex;
|
|
92
109
|
}
|
|
93
110
|
if (allAccounts.isError || allAccounts.error) {
|
|
@@ -98,16 +115,16 @@ class ThyraProvider {
|
|
|
98
115
|
// delete the account in question
|
|
99
116
|
let thyraAccountsResponse = null;
|
|
100
117
|
try {
|
|
101
|
-
thyraAccountsResponse = await (0, RequestHandler_1.deleteRequest)(`${exports.THYRA_ACCOUNTS_URL}
|
|
118
|
+
thyraAccountsResponse = await (0, RequestHandler_1.deleteRequest)(`${exports.THYRA_ACCOUNTS_URL}${accountToDelete.nickname}`);
|
|
102
119
|
}
|
|
103
120
|
catch (ex) {
|
|
104
|
-
console.
|
|
121
|
+
console.log(`Thyra accounts deletion error`, ex);
|
|
105
122
|
return {
|
|
106
123
|
response: AccountDeletion_1.EAccountDeletionResponse.ERROR,
|
|
107
124
|
};
|
|
108
125
|
}
|
|
109
126
|
if (thyraAccountsResponse.isError || thyraAccountsResponse.error) {
|
|
110
|
-
console.
|
|
127
|
+
console.log(`Thyra accounts deletion error`, thyraAccountsResponse.error.message);
|
|
111
128
|
return {
|
|
112
129
|
response: AccountDeletion_1.EAccountDeletionResponse.ERROR,
|
|
113
130
|
};
|
|
@@ -122,7 +139,20 @@ class ThyraProvider {
|
|
|
122
139
|
* @returns a Promise that resolves to a list of node urls.
|
|
123
140
|
*/
|
|
124
141
|
async getNodesUrls() {
|
|
125
|
-
|
|
142
|
+
let nodesResponse = null;
|
|
143
|
+
try {
|
|
144
|
+
nodesResponse = await (0, RequestHandler_1.getRequest)(`${exports.THYRA_URL}/massa/node`);
|
|
145
|
+
if (nodesResponse.isError || nodesResponse.error) {
|
|
146
|
+
throw nodesResponse.error.message;
|
|
147
|
+
}
|
|
148
|
+
// transform nodesResponse.result to a json and then get the "url" property
|
|
149
|
+
const nodes = nodesResponse.result;
|
|
150
|
+
return Array(nodes.url);
|
|
151
|
+
}
|
|
152
|
+
catch (ex) {
|
|
153
|
+
console.error(`Thyra nodes retrieval error`, ex);
|
|
154
|
+
throw ex;
|
|
155
|
+
}
|
|
126
156
|
}
|
|
127
157
|
/**
|
|
128
158
|
* This method sends an http call to the Thyra server to create a new random account.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThyraProvider.js","sourceRoot":"","sources":["../../src/thyra/ThyraProvider.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ThyraProvider.js","sourceRoot":"","sources":["../../src/thyra/ThyraProvider.ts"],"names":[],"mappings":";;;AAAA,iEAGqC;AACrC,6DAImC;AAEnC,qDAM0B;AAC1B,iDAA8C;AAI9C;;GAEG;AACU,QAAA,gBAAgB,GAC3B,6DAA6D,CAAC;AAEnD,QAAA,SAAS,GAAG,kBAAkB,CAAC;AAE5C;;GAEG;AACU,QAAA,kBAAkB,GAAG,GAAG,wBAAgB,eAAe,CAAC;AAErE;;GAEG;AACU,QAAA,mBAAmB,GAAG,OAAO,CAAC;AAgB3C;;;;GAIG;AACH,MAAa,aAAa;IAGxB;;;;;OAKG;IACH;QACE,IAAI,CAAC,YAAY,GAAG,2BAAmB,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,qBAAqB,GAA6C,IAAI,CAAC;QAC3E,IAAI;YACF,qBAAqB,GA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