```javascript
let net = {
- main : "http://main-net-host/",
+ main: "http://main-net-host/",
test: "http://test-net-host/"
};
let bytom = new Bytom(net, chrome.runtime.getURL("main.wasm"));
+//set Bytom net type (main test), default main net.
+bytom.setNetType('test');
+console.log(bytom.getNetType());
+
//create key
bytom.sdk.keys.create("test_alias", "123456").then((res)=>{
console.log(res)
{
"name": "bytom-js-sdk",
- "version": "1.3.0",
+ "version": "1.3.1",
"description": "Bytom JS SDK",
"main": "src/index.js",
"keywords" :[
Accept: 'application/json',
},
data: body,
- timeout: 1000
+ timeout: 2000
};
//return Promise
this.accounts = new accountsApi(this.http);
this.transactions = new transactionsApi(this.http);
}
-
+ this.net = 'main';
Bytom.wasmPath = wasmPath;
this.serverHttp = new serverHttp(serverHost);
this.sdk = {};
this.sdk.keys = new keysSDK();
- this.sdk.accounts = new accountsSDK(this.serverHttp);
- this.sdk.transaction = new transactionSDK(this.serverHttp);
+ this.sdk.accounts = new accountsSDK(this);
+ this.sdk.transaction = new transactionSDK(this);
this.sdk.wallet = new walletSDK(this);
}
+
+/**
+ * Get net type;
+ *
+ * @returns
+ */
+Bytom.prototype.getNetType = function() {
+ return this.net;
+};
+
+/**
+ * Set net type
+ *
+ * @param {String} net net type (main test)
+ */
+Bytom.prototype.setNetType = function(net) {
+ this.net = net;
+};
+
export default Bytom;
\ No newline at end of file
import {createAccount, createAccountReceiver} from '../wasm/func';
import {handleAxiosError} from '../utils/http';
-function accountsSDK(http){
- this.http = http;
+function accountsSDK(bytom){
+ this.http = bytom.serverHttp;
+ this.bytom = bytom;
}
/**
* List of the account.
*
- * @param {String} net list select net
* @returns {Promise}
*/
-accountsSDK.prototype.listAccountUseServer = function(net) {
- if (!net) {
- net = 'main';
- }
+accountsSDK.prototype.listAccountUseServer = function() {
+ let net = this.bytom.net;
let retPromise = new Promise((resolve, reject) => {
getDB().then(db => {
let transaction = db.transaction(['accounts-server'], 'readonly');
*
* @see https://gist.github.com/HAOYUatHZ/0c7446b8f33e7cddd590256b3824b08f#apiv1btmaccountlist-addresses
* @param {String} guid
- * @param {String} net server net
* @returns
*/
-accountsSDK.prototype.listAddressUseServer = function(guid, net) {
- if (!net) {
- net = 'main';
- }
+accountsSDK.prototype.listAddressUseServer = function(guid) {
+ let net = this.bytom.net;
let retPromise = new Promise((resolve, reject) => {
this.http.request('account/list-addresses', {guid:guid}, net).then(resp => {
resolve(resp.data.data.addresses);
* @see https://gist.github.com/HAOYUatHZ/0c7446b8f33e7cddd590256b3824b08f#apiv1btmaccountnew-address
* @param {String} guid unique id for each wallet
* @param {String} label alias for the address to be created
- * @param {String} net address net
* @returns {Promise}
*/
-accountsSDK.prototype.createAccountReceiverUseServer = function(guid, label, net) {
- if (!net) {
- net = 'main';
- }
+accountsSDK.prototype.createAccountReceiverUseServer = function(guid, label) {
+ let net = this.bytom.net;
let retPromise = new Promise((resolve, reject) => {
let pm = {guid: guid};
if (label) {
* @param {String} rootXPub
* @param {String} alias alias for the account
* @param {String} label alias for the first address
- * @param {String} net account net
* @returns {Promise}
*/
-accountsSDK.prototype.createAccountUseServer = function(rootXPub, alias, label, net) {
- if (!net) {
- net = 'main';
- }
+accountsSDK.prototype.createAccountUseServer = function(rootXPub, alias, label) {
+ let net = this.bytom.net;
let that = this;
let retPromise = new Promise((resolve, reject) => {
getDB().then(db => {
import {signTransaction} from '../wasm/func';
import {handleAxiosError} from '../utils/http';
-function transactionSDK(http) {
- this.http = http;
+function transactionSDK(bytom) {
+ this.http = bytom.serverHttp;
+ this.bytom = bytom;
}
* @returns {Promise}
*/
transactionSDK.prototype.list = function(guid, address) {
+ let net = this.bytom.net;
let retPromise = new Promise((resolve, reject) => {
let pm = {guid: guid};
if (address) {
pm.address = address;
}
- this.http.request('merchant/list-transactions', pm).then(resp => {
+ this.http.request('merchant/list-transactions', pm, net).then(resp => {
resolve(resp.data);
}).catch(err => {
reject(handleAxiosError(err));
* @param {Array} signatures signed data of each signing instruction
*/
transactionSDK.prototype.submitPayment = function(guid, raw_transaction, signatures) {
+ let net = this.bytom.net;
let retPromise = new Promise((resolve, reject) => {
let pm = {guid: guid, raw_transaction: raw_transaction, signatures: signatures};
- this.http.request('merchant/submit-payment', pm).then(resp => {
+ this.http.request('merchant/submit-payment', pm, net).then(resp => {
resolve(resp.data);
}).catch(err => {
reject(handleAxiosError(err));
* @returns {Promise}
*/
transactionSDK.prototype.buildPayment = function(guid, to, asset, amount, from, fee) {
+ let net = this.bytom.net;
let retPromise = new Promise((resolve, reject) => {
let pm = {guid: guid, to: to, asset: asset, amount: amount};
if (from) {
if (fee) {
pm.fee = fee;
}
- this.http.request('merchant/build-payment', pm).then(resp => {
+ this.http.request('merchant/build-payment', pm, net).then(resp => {
resolve(resp.data);
}).catch(err => {
reject(handleAxiosError(err));