Skip to content

Commit

Permalink
Fix chainx_rpc gen for return value on multi spanned lines (paritytec…
Browse files Browse the repository at this point in the history
…h#316)

* Fix chain_rpc gen for return value on multi spanned lines

* .
  • Loading branch information
liuchengxu authored Nov 2, 2020
1 parent 3d8a0bd commit f2954e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions scripts/chainx-js/res/chainx_rpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"isOptional": true
}
],
"type": "Page<Vec<RpcOrder<TradingPairId, AccountId, RpcBalance<Balance>, RpcPrice<Price>, BlockNumber>>>"
"type": "Page<Vec<RpcOrder<TradingPairId,AccountId,RpcBalance<Balance>,RpcPrice<Price>,BlockNumber>>>"
},
"getDepth": {
"description": "Get the depth of a trading pair.",
Expand Down Expand Up @@ -245,7 +245,7 @@
"isOptional": true
}
],
"type": "Vec<MiningAssetInfo<AccountId, RpcBalance<Balance>, RpcMiningWeight<MiningWeight>, BlockNumber>>"
"type": "Vec<MiningAssetInfo<AccountId,RpcBalance<Balance>,RpcMiningWeight<MiningWeight>,BlockNumber>>"
},
"getDividendByAccount": {
"description": "Get the asset mining dividends info given the asset miner AccountId.",
Expand Down Expand Up @@ -333,7 +333,7 @@
"isOptional": true
}
],
"type": "BTreeMap<AccountId, NominatorLedger<RpcBalance<Balance>, RpcVoteWeight<VoteWeight>, BlockNumber>>"
"type": "BTreeMap<AccountId,NominatorLedger<RpcBalance<Balance>, RpcVoteWeight<VoteWeight>, BlockNumber>>"
},
"getNominatorByAccount": {
"description": "Get individual nominator information given the nominator AccountId.",
Expand All @@ -351,4 +351,4 @@
"type": "NominatorInfo<BlockNumber>"
}
}
}
}
11 changes: 8 additions & 3 deletions scripts/chainx-js/types_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,22 @@ def parse_rpc_api(xmodule, description, inner_fn, line_fn):

params = parse_rpc_params(fn)

# .....<MiningWeight>,BlockNumber,>,>,>;
result = result.replace(',>', '>')
# Result<BTreeMap<AssetId, TotalAssetInfo>>;
# len('Result<') = 7
# >; = 2
ok_result = result[8:-2]
ok_type = result[8:-2]
rpc_dict[xmodule][inner_fn] = {
'description': description,
'params': params,
'type': ok_result
'type': ok_type
}


def build_rpc():
MAX_RETURN_VALUE_SPANNED_LINES = 100

# Assume all the API definition is in foo/rpc/src/lib.rs
rpc_rs_files = list(filter(lambda x: '/rpc/src/lib.rs' in x, rs_files))

Expand All @@ -422,7 +426,8 @@ def build_rpc():
if xmodule.startswith('x'):
fn_lines = []
# Normally the fn defintion won't more than 10 lines
for i in range(idx, idx + 10):
for i in range(idx, idx +
MAX_RETURN_VALUE_SPANNED_LINES):
fn_lines.append(lines[i].strip())
if lines[i].strip().endswith(';'):
break
Expand Down

0 comments on commit f2954e3

Please sign in to comment.