Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into momenttz
Browse files Browse the repository at this point in the history
  • Loading branch information
kwunyeung authored Sep 23, 2019
2 parents 75505c6 + cfba923 commit 3d15a14
Show file tree
Hide file tree
Showing 26 changed files with 592 additions and 343 deletions.
2 changes: 1 addition & 1 deletion .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ react-meteor-data@0.2.16
reactive-var@1.0.11
reload@1.3.0
retry@1.1.0
reywood:publish-composite@1.7.1
reywood:publish-composite@1.7.2
routepolicy@1.1.0
server-render@0.3.1
shell-server@0.4.0
Expand Down
24 changes: 12 additions & 12 deletions imports/api/accounts/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Meteor.methods({
try{
let available = HTTP.get(url);
if (available.statusCode == 200){
let response = JSON.parse(available.content);
let response = JSON.parse(available.content).result;
let account;
if (response.type === 'cosmos-sdk/Account')
account = response.value;
Expand All @@ -45,7 +45,7 @@ Meteor.methods({
let available = HTTP.get(url);
if (available.statusCode == 200){
// console.log(JSON.parse(available.content))
balance.available = JSON.parse(available.content);
balance.available = JSON.parse(available.content).result;
if (balance.available && balance.available.length > 0)
balance.available = balance.available[0];
}
Expand All @@ -59,7 +59,7 @@ Meteor.methods({
try{
let delegations = HTTP.get(url);
if (delegations.statusCode == 200){
balance.delegations = JSON.parse(delegations.content);
balance.delegations = JSON.parse(delegations.content).result;
}
}
catch (e){
Expand All @@ -70,7 +70,7 @@ Meteor.methods({
try{
let unbonding = HTTP.get(url);
if (unbonding.statusCode == 200){
balance.unbonding = JSON.parse(unbonding.content);
balance.unbonding = JSON.parse(unbonding.content).result;
}
}
catch (e){
Expand All @@ -82,7 +82,7 @@ Meteor.methods({
try{
let rewards = HTTP.get(url);
if (rewards.statusCode == 200){
balance.rewards = JSON.parse(rewards.content);
balance.rewards = JSON.parse(rewards.content).result.total;
}
}
catch (e){
Expand All @@ -98,7 +98,7 @@ Meteor.methods({
try {
let rewards = HTTP.get(url);
if (rewards.statusCode == 200){
let content = JSON.parse(rewards.content);
let content = JSON.parse(rewards.content).result;
if (content.val_commission && content.val_commission.length > 0)
balance.commission = content.val_commission[0];
}
Expand All @@ -114,13 +114,13 @@ Meteor.methods({
'accounts.getDelegation'(address, validator){
let url = `/staking/delegators/${address}/delegations/${validator}`;
let delegations = fetchFromUrl(url);
delegations = delegations && delegations.data;
delegations = delegations && delegations.data.result;
if (delegations && delegations.shares)
delegations.shares = parseFloat(delegations.shares);

url = `/staking/redelegations?delegator=${address}&validator_to=${validator}`;
let relegations = fetchFromUrl(url).data;
relegations = relegations && relegations.data;
let relegations = fetchFromUrl(url);
relegations = relegations && relegations.data.result;
let completionTime;
if (relegations) {
relegations.forEach((relegation) => {
Expand All @@ -134,7 +134,7 @@ Meteor.methods({

url = `/staking/delegators/${address}/unbonding_delegations/${validator}`;
let undelegations = fetchFromUrl(url);
undelegations = undelegations && undelegations.data;
undelegations = undelegations && undelegations.data.result;
if (undelegations) {
delegations.unbonding = undelegations.entries.length;
delegations.unbondingCompletionTime = undelegations.entries[0].completion_time;
Expand All @@ -147,7 +147,7 @@ Meteor.methods({
try{
let delegations = HTTP.get(url);
if (delegations.statusCode == 200){
delegations = JSON.parse(delegations.content);
delegations = JSON.parse(delegations.content).result;
if (delegations && delegations.length > 0){
delegations.forEach((delegation, i) => {
if (delegations[i] && delegations[i].shares)
Expand All @@ -168,7 +168,7 @@ Meteor.methods({
try{
let unbondings = HTTP.get(url);
if (unbondings.statusCode == 200){
unbondings = JSON.parse(unbondings.content);
unbondings = JSON.parse(unbondings.content).result;
return unbondings;
};
}
Expand Down
8 changes: 4 additions & 4 deletions imports/api/blocks/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Meteor.methods({

try{
response = HTTP.get(url);
JSON.parse(response.content).forEach((validator) => validatorSet[validator.consensus_pubkey] = validator);
JSON.parse(response.content).result.forEach((validator) => validatorSet[validator.consensus_pubkey] = validator);
}
catch(e){
console.log(e);
Expand All @@ -152,7 +152,7 @@ Meteor.methods({

try{
response = HTTP.get(url);
JSON.parse(response.content).forEach((validator) => validatorSet[validator.consensus_pubkey] = validator)
JSON.parse(response.content).result.forEach((validator) => validatorSet[validator.consensus_pubkey] = validator)
}
catch(e){
console.log(e);
Expand All @@ -162,7 +162,7 @@ Meteor.methods({

try{
response = HTTP.get(url);
JSON.parse(response.content).forEach((validator) => validatorSet[validator.consensus_pubkey] = validator)
JSON.parse(response.content).result.forEach((validator) => validatorSet[validator.consensus_pubkey] = validator)
}
catch(e){
console.log(e);
Expand Down Expand Up @@ -440,7 +440,7 @@ Meteor.methods({
let response = HTTP.get(LCD + '/staking/delegators/'+valExist.delegator_address+'/delegations/'+valExist.operator_address);

if (response.statusCode == 200){
let selfDelegation = JSON.parse(response.content);
let selfDelegation = JSON.parse(response.content).result;
if (selfDelegation.shares){
validator.self_delegation = parseFloat(selfDelegation.shares)/parseFloat(validator.delegator_shares);
}
Expand Down
16 changes: 9 additions & 7 deletions imports/api/chain/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Meteor.methods({
url = LCD + '/staking/pool';
try{
response = HTTP.get(url);
let bonding = JSON.parse(response.content);
let bonding = JSON.parse(response.content).result;
// chain.bondedTokens = bonding.bonded_tokens;
// chain.notBondedTokens = bonding.not_bonded_tokens;
chainStates.bondedTokens = parseInt(bonding.bonded_tokens);
Expand All @@ -92,7 +92,7 @@ Meteor.methods({
url = LCD + '/distribution/community_pool';
try {
response = HTTP.get(url);
let pool = JSON.parse(response.content);
let pool = JSON.parse(response.content).result;
if (pool && pool.length > 0){
chainStates.communityPool = [];
pool.forEach((amount, i) => {
Expand All @@ -110,7 +110,7 @@ Meteor.methods({
url = LCD + '/minting/inflation';
try{
response = HTTP.get(url);
let inflation = JSON.parse(response.content);
let inflation = JSON.parse(response.content).result;
if (inflation){
chainStates.inflation = parseFloat(inflation)
}
Expand Down Expand Up @@ -184,15 +184,17 @@ Meteor.methods({
},
slashing:{
params: genesis.app_state.slashing.params
}
},
supply: genesis.app_state.supply,
crisis: genesis.app_state.crisis
}

let totalVotingPower = 0;

// read gentx
if (genesis.app_state.gentxs && (genesis.app_state.gentxs.length > 0)){
for (i in genesis.app_state.gentxs){
let msg = genesis.app_state.gentxs[i].value.msg;
if (genesis.app_state.genutil && genesis.app_state.genutil.gentxs && (genesis.app_state.genutil.gentxs.length > 0)){
for (i in genesis.app_state.genutil.gentxs){
let msg = genesis.app_state.genutil.gentxs[i].value.msg;
// console.log(msg.type);
for (m in msg){
if (msg[m].type == "cosmos-sdk/MsgCreateValidator"){
Expand Down
2 changes: 1 addition & 1 deletion imports/api/delegations/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Meteor.methods({
try{
let response = HTTP.get(url);
if (response.statusCode == 200){
let delegation = JSON.parse(response.content);
let delegation = JSON.parse(response.content).result;
// console.log(delegation);
delegations = delegations.concat(delegation);
}
Expand Down
26 changes: 16 additions & 10 deletions imports/api/proposals/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ Meteor.methods({
try{
let url = LCD + '/gov/proposals';
let response = HTTP.get(url);
let proposals = JSON.parse(response.content);

let proposals = JSON.parse(response.content).result;
// console.log(proposals);

let finishedProposalIds = new Set(Proposals.find(
{"proposal_status":{$in:["Passed", "Rejected", "Removed"]}}
).fetch().map((p)=> p.proposalId));

let proposalIds = [];
if (proposals.length > 0){
// Proposals.upsert()
const bulkProposals = Proposals.rawCollection().initializeUnorderedBulkOp();
for (let i in proposals){
let proposal = proposals[i];
proposal.proposalId = parseInt(proposal.id);
if (proposal.proposalId > 0){
if (proposal.proposalId > 0 && !finishedProposalIds.has(proposal.proposalId)) {
try{
let url = LCD + '/gov/proposals/'+proposal.proposalId+'/proposer';
let response = HTTP.get(url);
if (response.statusCode == 200){
let proposer = JSON.parse(response.content);
let proposer = JSON.parse(response.content).result;
if (proposer.proposal_id && (proposer.proposal_id == proposal.id)){
proposal.proposer = proposer.proposer;
}
Expand All @@ -41,9 +44,11 @@ Meteor.methods({
}
}
}
bulkProposals.find({proposalId:{$nin:proposalIds}}).update({$set:{"value.proposal_status":"Removed"}});
bulkProposals.find({proposalId:{$nin:proposalIds}, proposal_status:{$nin:["Passed", "Rejected", "Removed"]}})
.update({$set: {"proposal_status": "Removed"}});
bulkProposals.execute();
}
return true
}
catch (e){
console.log(e);
Expand All @@ -62,21 +67,21 @@ Meteor.methods({
let response = HTTP.get(url);
let proposal = {proposalId: proposals[i].proposalId};
if (response.statusCode == 200){
let deposits = JSON.parse(response.content);
let deposits = JSON.parse(response.content).result;
proposal.deposits = deposits;
}

url = LCD + '/gov/proposals/'+proposals[i].proposalId+'/votes';
response = HTTP.get(url);
if (response.statusCode == 200){
let votes = JSON.parse(response.content);
let votes = JSON.parse(response.content).result;
proposal.votes = getVoteDetail(votes);
}

url = LCD + '/gov/proposals/'+proposals[i].proposalId+'/tally';
response = HTTP.get(url);
if (response.statusCode == 200){
let tally = JSON.parse(response.content);
let tally = JSON.parse(response.content).result;
proposal.tally = tally;
}

Expand All @@ -89,6 +94,7 @@ Meteor.methods({
}
}
}
return true
}
})

Expand Down Expand Up @@ -119,8 +125,8 @@ const getVoteDetail = (votes) => {
try{
let response = HTTP.get(url);
if (response.statusCode == 200){
delegations = JSON.parse(response.content);
if (delegations) {
delegations = JSON.parse(response.content).result;
if (delegations && delegations.length > 0) {
delegations.forEach((delegation) => {
let shares = parseFloat(delegation.shares);
if (validatorAddressMap[delegation.validator_address]) {
Expand Down
21 changes: 9 additions & 12 deletions imports/api/transactions/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,28 @@ Meteor.methods({
else return false;
},
'Transactions.findDelegation': function(address, height){
// following cosmos-sdk/x/slashing/spec/06_events.md and cosmos-sdk/x/staking/spec/06_events.md
return Transactions.find({
$or: [{$and: [
{"events.attributes.key": "action"},
{"events.attributes.value": "delegate"},
{"events.attributes.key": "destination-validator"},
{"events.type": "delegate"},
{"events.attributes.key": "validator"},
{"events.attributes.value": address}
]}, {$and:[
{"events.attributes.key": "action"},
{"events.attributes.value": "unjail"},
{"events.attributes.key": "validator"},
{"events.attributes.value": address}
]}, {$and:[
{"events.attributes.key": "action"},
{"events.attributes.value": "create_validator"},
{"events.attributes.key": "destination-validator"},
{"events.type": "create_validator"},
{"events.attributes.key": "validator"},
{"events.attributes.value": address}
]}, {$and:[
{"events.attributes.key": "action"},
{"events.attributes.value": "begin_unbonding"},
{"events.attributes.key": "source-validator"},
{"events.type": "unbond"},
{"events.attributes.key": "validator"},
{"events.attributes.value": address}
]}, {$and:[
{"events.attributes.key": "action"},
{"events.attributes.value": "begin_redelegate"},
{"events.attributes.key": "destination-validator"},
{"events.type": "redelegate"},
{"events.attributes.key": "destination_validator"},
{"events.attributes.value": address}
]}],
"code": {$exists: false},
Expand Down
2 changes: 1 addition & 1 deletion imports/api/validators/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Meteor.methods({
try{
let delegations = HTTP.get(url);
if (delegations.statusCode == 200){
delegations = JSON.parse(delegations.content);
delegations = JSON.parse(delegations.content).result;
delegations.forEach((delegation, i) => {
if (delegations[i] && delegations[i].shares)
delegations[i].shares = parseFloat(delegations[i].shares);
Expand Down
Loading

0 comments on commit 3d15a14

Please sign in to comment.