Skip to content

Commit

Permalink
Merge pull request #1 from crypt0sh0j0/move-to-eosjs
Browse files Browse the repository at this point in the history
feat: eosjs1 and able to fetch
  • Loading branch information
Crypt0Senpa1 authored Nov 1, 2018
2 parents 024af67 + 9c7a457 commit 1965246
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 62 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"buefy": "^0.7.0",
"core-decorators": "^0.20.0",
"d3-geo": "^1.11.1",
"eosjs": "20.0.0-beta1",
"eosjs": "16.0.9",
"eventemitter2": "^5.0.1",
"hammerjs": "^2.0.8",
"i18n-iso-countries": "^3.7.8",
Expand All @@ -22,6 +22,7 @@
"lodash-decorators": "^6.0.0",
"prejs": "^1.2.6",
"scatterjs-core": "^2.3.3",
"scatterjs-plugin-eosjs": "^1.3.9",
"scatterjs-plugin-eosjs2": "^1.1.5",
"three": "^0.97.0",
"vue": "^2.5.17",
Expand Down
2 changes: 1 addition & 1 deletion src/components/SponsorPaymentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default {
async payWithScatterAsync() {
this.isScatterPaying = true;
try {
await API.transferAsync({
await API.transferEOSAsync({
from: this.scatterAccount.name,
...this.transaction,
});
Expand Down
72 changes: 25 additions & 47 deletions src/util/api.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import ScatterJS from 'scatterjs-core';
import ScatterEOS from 'scatterjs-plugin-eosjs2';
import { Api, Rpc } from 'eosjs';
import ScatterEOS from 'scatterjs-plugin-eosjs';
import Eos from 'eosjs';
import * as config from '@/config';
import EosPriceFormatter from './eosPriceFormatter';

ScatterJS.plugins(new ScatterEOS());

const eosRpc = new Rpc.JsonRpc(`${config.network.protocol}://${config.network.host}:${config.network.port}`);
const eosApi = ScatterJS.scatter.eos(config.network, Api, { rpc: eosRpc });
// const eosRpc = new Rpc.JsonRpc(`${config.network.protocol}://${config.network.host}:${config.network.port}`);
// const eosApi = ScatterJS.scatter.eos(config.network, Api, { rpc: eosRpc });
const eos = ScatterJS.scatter.eos(config.network, Eos, { expireInSeconds: 60 });

const API = {
async getMyStakedInfoAsync({ accountName }) {
const { rows } = await eosRpc.get_table_rows({
const { rows } = await eos.getTableRows({
json: true,
code: 'cryptomeetup',
scope: accountName,
Expand All @@ -21,7 +22,7 @@ const API = {
return rows;
},
async getLandsInfoAsync() {
const { rows } = await eosRpc.get_table_rows({
const { rows } = await eos.getTableRows({
json: true,
code: 'cryptomeetup',
scope: 'cryptomeetup',
Expand All @@ -31,7 +32,7 @@ const API = {
return rows;
},
async getMarketInfoAsync() {
const { rows } = await eosRpc.get_table_rows({
const { rows } = await eos.getTableRows({
json: true,
code: 'cryptomeetup',
scope: 'cryptomeetup',
Expand All @@ -41,7 +42,7 @@ const API = {
return rows;
},
async getBalancesByContract({ tokenContract = 'eosio.token', accountName, symbol }) {
return eosRpc.get_currency_balance(tokenContract, accountName, symbol);
return eos.getCurrencyBalance(tokenContract, accountName, symbol);
},
getNextPrice(land) {
return land.price * 1.4;
Expand Down Expand Up @@ -71,52 +72,29 @@ const API = {
memo = '',
amount = 0,
}) {
return eosApi.transact({
actions: [{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: from,
permission: 'active',
}],
data: {
from,
to,
quantity: EosPriceFormatter.formatPrice(amount),
memo,
},
}],
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(ScatterJS.scatter.identity);
return eos.transfer(
from,
to,
EosPriceFormatter.formatPrice(amount),
memo, {
authorization: [`${from.name}@active`],
});
},
transferTokenAsync({
async transferTokenAsync({
from,
to,
memo = '',
amount = 0,
tokenContract = 'eosio.token',
}) {
return eosApi.transact({
actions: [{
account: tokenContract,
name: 'transfer',
authorization: [{
actor: from,
permission: 'active',
}],
data: {
from,
to,
quantity: amount,
memo,
},
}],
}, {
blocksBehind: 3,
expireSeconds: 30,
});
const contract = await eos.contract(tokenContract);
return contract.transfer(from,
to,
amount,
memo, {
authorization: [`${from.name}@active`],
});
},
};

Expand Down
79 changes: 66 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ babel-polyfill@^6.26.0:
core-js "^2.5.0"
regenerator-runtime "^0.10.5"

babel-runtime@^6.26.0:
babel-runtime@6.26.0, babel-runtime@^6.26.0:
version "6.26.0"
resolved "http://registry.npm.taobao.org/babel-runtime/download/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
dependencies:
Expand Down Expand Up @@ -1426,6 +1426,10 @@ binary-extensions@^1.0.0:
version "1.12.0"
resolved "http://registry.npm.taobao.org/binary-extensions/download/binary-extensions-1.12.0.tgz#c2d780f53d45bba8317a8902d4ceeaf3a6385b14"

binaryen@^37.0.0:
version "37.0.0"
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-37.0.0.tgz#c392bc784b6d46da8fc918b1a4ed8257a0cd8b08"

block-stream@*:
version "0.0.9"
resolved "http://registry.npm.taobao.org/block-stream/download/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a"
Expand All @@ -1436,7 +1440,7 @@ bluebird@^3.1.1, bluebird@^3.5.1:
version "3.5.2"
resolved "http://registry.npm.taobao.org/bluebird/download/bluebird-3.5.2.tgz#1be0908e054a751754549c270489c1505d4ab15a"

bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.8, bn.js@^4.4.0:
version "4.11.8"
resolved "http://registry.npm.taobao.org/bn.js/download/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"

Expand Down Expand Up @@ -1681,7 +1685,7 @@ callsites@^0.2.0:
version "0.2.0"
resolved "http://registry.npm.taobao.org/callsites/download/callsites-0.2.0.tgz#afab96262910a7f33c19a5775825c69f34e350ca"

camel-case@3.0.x:
camel-case@3.0.x, camel-case@^3.0.0:
version "3.0.0"
resolved "http://registry.npm.taobao.org/camel-case/download/camel-case-3.0.0.tgz#ca3c3688a4e9cf3a4cda777dc4dcbc713249cf73"
dependencies:
Expand Down Expand Up @@ -2652,6 +2656,12 @@ encodeurl@~1.0.2:
version "1.0.2"
resolved "http://registry.npm.taobao.org/encodeurl/download/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"

encoding@^0.1.11:
version "0.1.12"
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
dependencies:
iconv-lite "~0.4.13"

end-of-stream@^1.0.0, end-of-stream@^1.1.0:
version "1.4.1"
resolved "http://registry.npm.taobao.org/end-of-stream/download/end-of-stream-1.4.1.tgz#ed29634d19baba463b6ce6b80a37213eab71ec43"
Expand All @@ -2678,7 +2688,14 @@ entities@~1.1.1:
version "1.1.2"
resolved "http://registry.npm.taobao.org/entities/download/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"

eosjs-ecc@^4.0.1:
eosjs-api@7.0.4:
version "7.0.4"
resolved "https://registry.yarnpkg.com/eosjs-api/-/eosjs-api-7.0.4.tgz#dc3a7206d4ac3e6818f0a950b8d24333175ac7c9"
dependencies:
camel-case "^3.0.0"
isomorphic-fetch "^2.2.1"

eosjs-ecc@4.0.4, eosjs-ecc@^4.0.1:
version "4.0.4"
resolved "http://registry.npm.taobao.org/eosjs-ecc/download/eosjs-ecc-4.0.4.tgz#431450f30a6f73088ff5d7ba1ebdfe967a5ca4ab"
dependencies:
Expand All @@ -2691,14 +2708,16 @@ eosjs-ecc@^4.0.1:
ecurve "^1.0.5"
randombytes "^2.0.5"

eosjs@20.0.0-beta1:
version "20.0.0-beta1"
resolved "http://registry.npm.taobao.org/eosjs/download/eosjs-20.0.0-beta1.tgz#2c69329c503902e058f6fa1e4fdb1e4ce73f1f0e"
eosjs@16.0.9:
version "16.0.9"
resolved "https://registry.yarnpkg.com/eosjs/-/eosjs-16.0.9.tgz#ee3790f2f038079e71981f20354be8d1d98de873"
dependencies:
"@types/jest" "^23.3.1"
babel-polyfill "^6.26.0"
eosjs-ecc "^4.0.1"
text-encoding "^0.6.4"
babel-runtime "6.26.0"
binaryen "^37.0.0"
create-hash "^1.1.3"
eosjs-api "7.0.4"
eosjs-ecc "4.0.4"
fcbuffer "2.2.2"

eosjs@^20.0.0-beta1:
version "20.0.0-beta2"
Expand Down Expand Up @@ -3138,6 +3157,14 @@ faye-websocket@~0.11.0:
dependencies:
websocket-driver ">=0.5.1"

fcbuffer@2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/fcbuffer/-/fcbuffer-2.2.2.tgz#987d10062c46a8bfea27da77c964f43e9e25a014"
dependencies:
bn.js "^4.11.8"
bytebuffer "^5.0.1"
ieee-float "^0.6.0"

figgy-pudding@^3.5.1:
version "3.5.1"
resolved "http://registry.npm.taobao.org/figgy-pudding/download/figgy-pudding-3.5.1.tgz#862470112901c727a0e495a80744bd5baa1d6790"
Expand Down Expand Up @@ -3760,7 +3787,7 @@ iconv-lite@0.4.23:
dependencies:
safer-buffer ">= 2.1.2 < 3"

iconv-lite@^0.4.17, iconv-lite@^0.4.4:
iconv-lite@^0.4.17, iconv-lite@^0.4.4, iconv-lite@~0.4.13:
version "0.4.24"
resolved "http://registry.npm.taobao.org/iconv-lite/download/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
dependencies:
Expand All @@ -3776,6 +3803,10 @@ icss-utils@^2.1.0:
dependencies:
postcss "^6.0.1"

ieee-float@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/ieee-float/-/ieee-float-0.6.0.tgz#a68a856ba1ef511e7fa0e7e7e155c3a63642a55d"

ieee754@^1.1.4:
version "1.1.12"
resolved "http://registry.npm.taobao.org/ieee754/download/ieee754-1.1.12.tgz#50bf24e5b9c8bb98af4964c941cdb0918da7b60b"
Expand Down Expand Up @@ -4150,7 +4181,7 @@ is-resolvable@^1.0.0:
version "1.1.0"
resolved "http://registry.npm.taobao.org/is-resolvable/download/is-resolvable-1.1.0.tgz#fb18f87ce1feb925169c9a407c19318a3206ed88"

is-stream@^1.1.0:
is-stream@^1.0.1, is-stream@^1.1.0:
version "1.1.0"
resolved "http://registry.npm.taobao.org/is-stream/download/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"

Expand Down Expand Up @@ -4224,6 +4255,13 @@ isobject@^3.0.0, isobject@^3.0.1:
version "3.0.1"
resolved "http://registry.npm.taobao.org/isobject/download/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"

isomorphic-fetch@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
dependencies:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"

isstream@~0.1.2:
version "0.1.2"
resolved "http://registry.npm.taobao.org/isstream/download/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
Expand Down Expand Up @@ -4880,6 +4918,13 @@ no-case@^2.2.0:
dependencies:
lower-case "^1.1.1"

node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
dependencies:
encoding "^0.1.11"
is-stream "^1.0.1"

node-forge@0.7.5:
version "0.7.5"
resolved "http://registry.npm.taobao.org/node-forge/download/node-forge-0.7.5.tgz#6c152c345ce11c52f465c2abd957e8639cd674df"
Expand Down Expand Up @@ -6307,6 +6352,10 @@ scatterjs-plugin-eosjs2@^1.1.5:
dependencies:
eosjs "^20.0.0-beta1"

scatterjs-plugin-eosjs@^1.3.9:
version "1.3.9"
resolved "https://registry.yarnpkg.com/scatterjs-plugin-eosjs/-/scatterjs-plugin-eosjs-1.3.9.tgz#022aef153bea9c2b76bc4271e59aa8b4ef21404d"

schema-utils@^0.4.0, schema-utils@^0.4.2, schema-utils@^0.4.4, schema-utils@^0.4.5:
version "0.4.7"
resolved "http://registry.npm.taobao.org/schema-utils/download/schema-utils-0.4.7.tgz#ba74f597d2be2ea880131746ee17d0a093c68187"
Expand Down Expand Up @@ -7426,6 +7475,10 @@ websocket-extensions@>=0.1.1:
version "0.1.3"
resolved "http://registry.npm.taobao.org/websocket-extensions/download/websocket-extensions-0.1.3.tgz#5d2ff22977003ec687a4b87073dfbbac146ccf29"

whatwg-fetch@>=0.10.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb"

which-module@^1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/which-module/download/which-module-1.0.0.tgz#bba63ca861948994ff307736089e3b96026c2a4f"
Expand Down

0 comments on commit 1965246

Please sign in to comment.