示例#1
0
def wait_until(method, req, predict):
    resp = rpc_call(method, req)
    result = resp["result"]
    while not predict(result):
        time.sleep(1.0)
        resp = rpc_call(method, req)
        result = resp["result"]
    return result
示例#2
0
def wait_for(blocks):
    resp = rpc_call('query.ListValidators', {})
    hstart = resp["result"]["height"]
    hcur = hstart
    while hcur - hstart < blocks:
        time.sleep(0.5)
        resp = rpc_call('query.ListValidators', {})
        hcur = resp["result"]["height"]
示例#3
0
def broadcast_async(raw_tx, signature, pub_key):
    resp = rpc_call('broadcast.TxAsync', {
        "rawTx": raw_tx,
        "signature": signature,
        "publicKey": pub_key,
    })
    return resp["result"]
示例#4
0
def query_governanceState():
    req = {}
    resp = rpc_call('query.GetGovernanceOptionsForHeight', req)
    result = resp["result"]

    # print json.dumps(resp, indent=4)
    return result
示例#5
0
    def _create_proposal_invalid_info(self, invalid_field):
        _proposal_info = self._calculate_proposal_info(12)
        req = {
            "proposalId": self.get_encoded_pid(),
            "headline": self.headline,
            "description": self.des,
            "proposer": self.proposer,
            "proposalType": self.pty,
            "initialFunding": {
                "currency": "OLT",
                "value": convertBigInt(self.init_fund),
            },
            "fundingGoal": _proposal_info.funding_goal,
            "fundingDeadline": _proposal_info.funding_deadline,
            "votingDeadline": _proposal_info.voting_deadline,
            "passPercentage": _proposal_info.pass_percentage,
            "gasPrice": {
                "currency": "OLT",
                "value": "1000000000",
            },
            "gas": 40000,
        }
        if invalid_field == 0:
            req["fundingGoal"] = "123"
        elif invalid_field == 1:
            req["fundingDeadline"] = 0
        elif invalid_field == 2:
            req["votingDeadline"] = 0
        elif invalid_field == 3:
            req["passPercentage"] = 1

        resp = rpc_call('tx.CreateProposal', req)
        return resp["result"]["rawTx"]
示例#6
0
def get_funds_for_proposal_by_funder(proposalId, funder):
    req = {"proposalId": proposalId, "funderAddress": funder}
    resp = rpc_call('query.GetFundsForProposalByFunder', req)
    if "result" not in resp:
        sys.exit(-1)

    return resp["result"]
示例#7
0
 def _create_proposal(self):
     _proposal_info = self._calculate_proposal_info(12)
     req = {
         "proposalId": self.get_encoded_pid(),
         "headline": self.headline,
         "description": self.des,
         "proposer": self.proposer,
         "proposalType": self.pty,
         "initialFunding": {
             "currency": "OLT",
             "value": convertBigInt(self.init_fund),
         },
         "fundingGoal": _proposal_info.funding_goal,
         "fundingDeadline": _proposal_info.funding_deadline,
         "votingDeadline": _proposal_info.voting_deadline,
         "passPercentage": _proposal_info.pass_percentage,
         "configUpdate": self.configupdate,
         "gasPrice": {
             "currency": "OLT",
             "value": "1000000000",
         },
         "gas": 400000,
     }
     resp = rpc_call('tx.CreateProposal', req)
     return resp["result"]["rawTx"]
示例#8
0
def query_proposal(proposal_id):
    req = {
        "proposalId": proposal_id,
    }
    resp = rpc_call('query.ListProposal', req)
    stat = resp["result"]["proposalStats"][0]
    # print json.dumps(resp, indent=4)
    return stat["proposal"], stat["funds"]
示例#9
0
def query_bidConv(bidConv_Id):
    req = {
        "bidConvId": bidConv_Id,
    }
    resp = rpc_call('bid_query.ShowBidConv', req)
    result = resp["result"]
    print json.dumps(resp, indent=4)
    return result
示例#10
0
 def _withdraw_reward(self):
     req = {
         "validatorSigningAddress": self.address,
         "withdrawAmount": self.withdrawAmount,
     }
     resp = rpc_call('tx.WithdrawRewards', req)
     result = resp["result"]
     return result["rawTx"]
示例#11
0
def query_balance(address):
    req = {"currency": "OLT", "address": address}
    resp = rpc_call('query.CurrencyBalance', req)

    if "result" in resp:
        result = resp["result"]["balance"]
    else:
        result = ""
    return int(float(result))
示例#12
0
def query_total_rewards():
    resp = rpc_call('query.GetTotalRewards', {})

    if "result" in resp:
        result = resp["result"]
    else:
        result = ""

    return result
示例#13
0
def broadcast_commit(raw_tx, signature, pub_key):
    resp = rpc_call('broadcast.TxCommit', {
        "rawTx": raw_tx,
        "signature": signature,
        "publicKey": pub_key,
    })
    if "result" in resp:
        return resp["result"]
    else:
        return resp
示例#14
0
def broadcast_commit_mtsig(raw_tx, sigs):
    resp = rpc_call('broadcast.TxCommitMtSig', {
        "rawTx": raw_tx,
        "signatures": sigs,
    })
    print resp
    if "result" in resp:
        return resp["result"]
    else:
        return resp
示例#15
0
def sign_with_wallet(raw_tx, address, keypath):
    resp = rpc_call(
        'owner.SignWithSecureAddress', {
            "rawTx": raw_tx,
            "address": address,
            "password": "******",
            "keypath": keypath
        })
    print resp
    return resp["result"]
示例#16
0
def query_all_rewards(validator):
    req = {
        "validator": validator,
    }

    resp = rpc_call('query.ListRewardsForValidator', req)

    if "result" in resp:
        result = resp["result"]
    else:
        result = ""
    return result
示例#17
0
 def _cancel_bid(self, id):
     req = {
         "bidConvId": id,
         "bidder": self.bidder,
         "gasPrice": {
             "currency": "OLT",
             "value": "1000000000",
         },
         "gas": 400000,
     }
     resp = rpc_call('bid_tx.CancelBid', req)
     return resp["result"]["rawTx"]
示例#18
0
def query_proposals(prefix, proposer="", proposalType=ProposalTypeInvalid):
    req = {
        "state": prefix,
        "proposer": proposer,
        "proposalType": proposalType,
    }

    resp = rpc_call('query.ListProposals', req)
    # print resp
    result = resp["result"]
    # print json.dumps(resp, indent=4)
    return result["proposalStats"]
示例#19
0
def query_proposal_options():
    req = {}
    resp = rpc_call('query.GetProposalOptions', req)

    if "result" not in resp:
        sys.exit(-1)
    if "proposalOptions" not in resp["result"]:
        sys.exit(-1)
    if "height" not in resp["result"]:
        sys.exit(-1)
    # print json.dumps(resp, indent=4)
    return resp["result"]
示例#20
0
 def _finalize_proposal(self):
     req = {
         "proposalId": self.pid,
         "proposer": self.proposer,
         "gasPrice": {
             "currency": "OLT",
             "value": "1000000000",
         },
         "gas": 40000,
     }
     resp = rpc_call('tx.FinalizeProposal', req)
     return resp["result"]["rawTx"]
示例#21
0
def query_matured_rewards(validator):
    req = {
        "validator": validator
    }

    resp = rpc_call('query.GetTotalRewardsForValidator', req)

    if "result" in resp:
        result = resp["result"]
    else:
        result = ""
    return result
示例#22
0
 def _owner_decision(self, id, decision):
     req = {
         "bidConvId": id,
         "owner": self.owner,
         "decision": decision,
         "gasPrice": {
             "currency": "OLT",
             "value": "1000000000",
         },
         "gas": 400000,
     }
     resp = rpc_call('bid_tx.OwnerDecision', req)
     return resp["result"]["rawTx"]
示例#23
0
    def _cancel_proposal(self):
        req = {
            "proposalId": self.pid,
            "proposer": self.proposer,
            "reason": self.reason,
            "gasPrice": {
                "currency": "OLT",
                "value": "1000000000",
            },
            "gas": 40000,
        }

        resp = rpc_call('tx.CancelProposal', req)
        return resp["result"]["rawTx"]
示例#24
0
def sign(raw_tx, address, keypath):
    if is_docker():
        keypath = './keystore/'
    resp = rpc_call(
        'owner.SignWithSecureAddress', {
            "rawTx": raw_tx,
            "address": address,
            "password": "******",
            "keypath": keypath
        })
    if "result" in resp:
        return resp["result"]
    else:
        return resp
示例#25
0
def query_bidConvs(state, owner, assetName, assetType, bidder):
    req = {
        "state": state,
        "owner": owner,
        "assetName": assetName,
        "assetType": assetType,
        "bidder": bidder,
    }

    resp = rpc_call('bid_query.ListBidConvs', req)
    # print resp
    result = resp["result"]
    print json.dumps(resp, indent=4)
    return result
示例#26
0
 def _vote_proposal(self):
     req = {
         "proposalId": self.pid,
         "opinion": self.opin,
         "address": self.address,
         "gasPrice": {
             "currency": "OLT",
             "value": "1000000000",
         },
         "gas": 40000,
     }
     resp = rpc_call('tx.VoteProposal', req, self.voter)
     result = resp["result"]
     return result["rawTx"], result['signature']['Signed'], result[
         'signature']['Signer']
示例#27
0
def withdraw_rewards(validator):
    req = {
        "validator": validator,
        "gasPrice": {
            "currency": "OLT",
            "value": "1000000000",
        },
        "gas": 40000,
    }
    resp = rpc_call('tx.WithdrawRewards', req)
    if "result" in resp:
        result = resp["result"]
    else:
        result = ""
    return result
示例#28
0
 def _add_bid_offer(self, id):
     req = {
         "bidConvId": id,
         "bidder": self.bidder,
         "amount": {
             "currency": "OLT",
             "value": convertBigInt(self.counter_bid_amount),
         },
         "gasPrice": {
             "currency": "OLT",
             "value": "1000000000",
         },
         "gas": 400000,
     }
     resp = rpc_call('bid_tx.CreateBid', req)
     return resp["result"]["rawTx"]
示例#29
0
 def _counter_offer(self, id):
     req = {
         "bidConvId": id,
         "assetOwner": self.owner,
         "amount": {
             "currency": "OLT",
             "value": convertBigInt(self.counter_amount),
         },
         "gasPrice": {
             "currency": "OLT",
             "value": "1000000000",
         },
         "gas": 400000,
     }
     resp = rpc_call('bid_tx.CounterOffer', req)
     return resp["result"]["rawTx"]
示例#30
0
def create_domain(name, owner_hex, price):
    req = {
        "name": name,
        "owner": owner_hex,
        "account": owner_hex,
        "buyingPrice": {
            "currency": "OLT",
            "value": convertBigInt(price),
        },
        "gasPrice": {
            "currency": "OLT",
            "value": "1000000000",
        },
        "gas": 40000,
    }
    resp = rpc_call('tx.ONS_CreateRawCreate', req)
    return resp["result"]["rawTx"]