createLimitOrder(account, sellAmount, sellAsset, buyAmount, buyAsset, expiration, isFillOrKill, fee_asset_id) { var tr = wallet_api.new_transaction(); let feeAsset = ChainStore.getAsset(fee_asset_id); if( feeAsset.getIn(["options", "core_exchange_rate", "base", "asset_id"]) === "1.3.0" && feeAsset.getIn(["options", "core_exchange_rate", "quote", "asset_id"]) === "1.3.0" ) { fee_asset_id = "1.3.0"; } tr.add_type_operation("limit_order_create", { fee: { amount: 0, asset_id: fee_asset_id }, "seller": account, "amount_to_sell": { "amount": sellAmount, "asset_id": sellAsset.get("id") }, "min_to_receive": { "amount": buyAmount, "asset_id": buyAsset.get("id") }, "expiration": expiration, "fill_or_kill": isFillOrKill }); return WalletDb.process_transaction(tr, null, true).then(result => { return true; }) .catch(error => { console.log("order error:", error); return {error}; }); }
setTimeout(() => { let asset = ChainStore.getAsset(symbol); if (asset) { this.dispatch({ assets: [asset], searchID: searchID, symbol: symbol }); } }, 200);
lookupAsset(symbol, searchID) { let asset = ChainStore.getAsset(symbol); if (asset) { this.dispatch({ assets: [asset], searchID: searchID, symbol: symbol }); } else { // Hack to retry once until we replace this method with a new api call to lookup multiple assets setTimeout(() => { let asset = ChainStore.getAsset(symbol); if (asset) { this.dispatch({ assets: [asset], searchID: searchID, symbol: symbol }); } }, 200); } }
updateAsset(issuer, new_issuer, update, core_exchange_rate, asset, flags, permissions) { // Create asset action here... let tr = wallet_api.new_transaction(); let quotePrecision = utils.get_asset_precision(asset.get("precision")); big.config({DECIMAL_PLACES: asset.get("precision")}); let max_supply = (new big(update.max_supply)).times(quotePrecision).toString(); let max_market_fee = (new big(update.max_market_fee || 0)).times(quotePrecision).toString(); let cr_quote_asset = ChainStore.getAsset(core_exchange_rate.quote.asset_id); let cr_quote_precision = utils.get_asset_precision(cr_quote_asset.get("precision")); let cr_base_asset = ChainStore.getAsset(core_exchange_rate.base.asset_id); let cr_base_precision = utils.get_asset_precision(cr_base_asset.get("precision")); let cr_quote_amount = (new big(core_exchange_rate.quote.amount)).times(cr_quote_precision).toString(); let cr_base_amount = (new big(core_exchange_rate.base.amount)).times(cr_base_precision).toString(); let updateObject = { fee: { amount: 0, asset_id: 0 }, asset_to_update: asset.get("id"), extensions: asset.get("extensions"), issuer: issuer, new_issuer: new_issuer, new_options: { max_supply: max_supply, max_market_fee: max_market_fee, market_fee_percent: update.market_fee_percent * 100, description: update.description, issuer_permissions: permissions, flags: flags, whitelist_authorities: asset.getIn(["options", "whitelist_authorities"]), blacklist_authorities: asset.getIn(["options", "blacklist_authorities"]), whitelist_markets: asset.getIn(["options", "whitelist_markets"]), blacklist_markets: asset.getIn(["options", "blacklist_markets"]), extensions: asset.getIn(["options", "extensions"]), core_exchange_rate: { quote: { amount: cr_quote_amount, asset_id: core_exchange_rate.quote.asset_id }, base: { amount: cr_base_amount, asset_id: core_exchange_rate.base.asset_id } } } }; if (issuer === new_issuer || !new_issuer) { delete updateObject.new_issuer; } tr.add_type_operation("asset_update", updateObject); return WalletDb.process_transaction(tr, null, true).then(result => { // console.log("asset create result:", result); // this.dispatch(account_id); return true; }).catch(error => { console.log("[AssetActions.js:150] ----- createAsset error ----->", error); return false; }); }
createAsset(account_id, createObject, flags, permissions) { // Create asset action here... console.log("create asset:", createObject, "flags:", flags, "permissions:", permissions); let tr = wallet_api.new_transaction(); let precision = utils.get_asset_precision(createObject.precision); big.config({DECIMAL_PLACES: createObject.precision}); let max_supply = (new big(createObject.max_supply)).times(precision).toString(); let max_market_fee = (new big(createObject.max_market_fee || 0)).times(precision).toString(); // console.log("max_supply:", max_supply); // console.log("max_market_fee:", max_market_fee); let corePrecision = utils.get_asset_precision(ChainStore.getAsset("1.3.0").get("precision")); tr.add_type_operation("asset_create", { "fee": { amount: 0, asset_id: 0 }, "issuer": account_id, "symbol": createObject.symbol, "precision": parseInt(createObject.precision, 10), "common_options": { "max_supply": max_supply, "market_fee_percent": createObject.market_fee_percent * 100 || 0, "max_market_fee": max_market_fee, "issuer_permissions": permissions, "flags": flags, "core_exchange_rate": { "base": { "amount": 1 * corePrecision, "asset_id": "1.3.0" }, "quote": { "amount": 1 * precision, "asset_id": "1.3.1" } }, "whitelist_authorities": [ ], "blacklist_authorities": [ ], "whitelist_markets": [ ], "blacklist_markets": [ ], "description": createObject.description, "extensions": null }, "is_prediction_market": false, "extensions": null }); return WalletDb.process_transaction(tr, null, true).then(result => { // console.log("asset create result:", result); // this.dispatch(account_id); return true; }).catch(error => { console.log("[AssetActions.js:150] ----- createAsset error ----->", error); return false; }); }
return Promise.all([lookup_promise, unlock_promise]).then(()=> { var asset_id = asset_id_lookup.resolve if( propose_account ) propose_acount_id = propose_acount_id.resolve var memo_from_privkey if(encrypt_memo && memo ) { var from_public = memo_from_public.resolve memo_from_privkey = WalletDb.getPrivateKey(from_public) if(! memo_from_privkey) throw new Error("Missing private memo key for sender: " + memo_sender) } var memo_object if(memo && memo_to_public.resolve && memo_from_public.resolve) { var nonce = optional_nonce == null ? helper.unique_nonce_uint64() : optional_nonce memo_object = { from: memo_from_public.resolve, to: memo_to_public.resolve, nonce, message: (encrypt_memo) ? Aes.encrypt_with_checksum( memo_from_privkey, memo_to_public.resolve, nonce, memo ) : Buffer.isBuffer(memo) ? memo.toString("utf-8") : memo } } let fee_asset = ChainStore.getAsset( fee_asset_id ).toJS(); // let fee_asset_id = asset_id; if( fee_asset.options.core_exchange_rate.base.asset_id == "1.3.0" && fee_asset.options.core_exchange_rate.quote.asset_id == "1.3.0" ) fee_asset_id = "1.3.0"; var tr = new ops.signed_transaction() var transfer_op = tr.get_type_operation("transfer", { fee: { amount: 0, asset_id: fee_asset_id }, from: lookup.account_id(from_account), to: lookup.account_id(to_account), amount: { amount, asset_id}, //lookup.asset_id( memo: memo_object }) if( propose_account ) tr.add_type_operation("proposal_create", { proposed_ops: [{ op: transfer_op }], fee_paying_account: propose_acount_id }) else tr.add_operation( transfer_op ) return WalletDb.process_transaction( tr, null, //signer_private_keys, broadcast, sign ) })
onSubscribeMarket(result) { if (result.switchMarket) { this.marketReady = false; return true; } // console.log("onSubscribeMarket:", result, this.activeMarket); this.invertedCalls = result.inverted; // Get updated assets every time for updated feed data this.quoteAsset = ChainStore.getAsset(result.quote.get("id")); this.baseAsset = ChainStore.getAsset(result.base.get("id")); if (result.market && (result.market !== this.activeMarket)) { // console.log("switch active market from", this.activeMarket, "to", result.market); this.activeMarket = result.market; this.onClearMarket(); } if (result.buckets) { this.buckets = result.buckets; } if (result.limits) { // Keep an eye on this as the number of orders increases, it might not scale well let limitStart = new Date(); this.activeMarketLimits = this.activeMarketLimits.clear(); result.limits.forEach(order => { ChainStore._updateObject(order, false, false); if (typeof order.for_sale !== "number") { order.for_sale = parseInt(order.for_sale, 10); } order.expiration = new Date(order.expiration); this.activeMarketLimits = this.activeMarketLimits.set( order.id, LimitOrder(order) ); }); // Loop over pending orders to remove temp order from orders map and remove from pending for (let i = this.pendingCreateLimitOrders.length - 1; i >= 0; i--) { let myOrder = this.pendingCreateLimitOrders[i]; let order = this.activeMarketLimits.find((order, key) => { return myOrder.seller === order.seller && myOrder.expiration === order.expiration; }); // If the order was found it has been confirmed, delete it from pending if (order) { this.pendingCreateLimitOrders.splice(i, 1); } } if (this.pendingCreateLimitOrders.length === 0) { this.pendingCounter = 0; } console.log("time to process limit orders:", new Date() - limitStart, "ms"); } if (result.calls) { this.activeMarketCalls = this.activeMarketCalls.clear(); result.calls.forEach(call => { ChainStore._updateObject(call, false, false); if (typeof call.collateral !== "number") { call.collateral = parseInt(call.collateral, 10); } if (typeof call.debt !== "number") { call.debt = parseInt(call.debt, 10); } this.activeMarketCalls = this.activeMarketCalls.set( call.id, CallOrder(call) ); }); } this.updateSettleOrders(result); if (result.history) { this.activeMarketHistory = this.activeMarketHistory.clear(); result.history.forEach(order => { order.op.time = order.time; this.activeMarketHistory = this.activeMarketHistory.add( order.op ); }); } if (result.fillOrders) { result.fillOrders.forEach(fill => { // console.log("fill:", fill); this.activeMarketHistory = this.activeMarketHistory.add( fill[0][1] ); }); } if (result.recent && result.recent.length) { let stats = this._calcMarketStats(result.recent, this.baseAsset, this.quoteAsset); this.marketStats = this.marketStats.set("change", stats.change); this.marketStats = this.marketStats.set("volumeBase", stats.volumeBase); this.marketStats = this.marketStats.set("volumeQuote", stats.volumeQuote); } // Update orderbook this._orderBook(); // Update depth chart data this._depthChart(); // Update pricechart data if (result.price) { this.priceHistory = result.price; this._priceChart(); } this.marketReady = true; }