Example #1
0
def verifySignature(ontId,
                    keyNum,
                    public_key,
                    node_index=None,
                    errorcode=47001):
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signativeinvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "method": "verifySignature",
                "address": "0300000000000000000000000000000000000000",
                "version": 1,
                "params": [ontId, keyNum]
            }
        },
        "RESPONSE": {
            "error": errorcode
        }
    }

    if node_index != None:
        request["NODE_INDEX"] = node_index
    else:
        node_index = Common.ontid_map[public_key]
        request["NODE_INDEX"] = node_index

    return call_contract(Task(name="verifySignature", ijson=request),
                         twice=True)
Example #2
0
 def getmerkleproofbytxhash(self, _hash):
     task = Task(Config.BASEAPI_PATH + "/restful/get_merkle_proof.json")
     task.set_type("restful")
     taskrequest = task.request()
     taskrequest["api"] = "/api/v1/merkleproof/" + str(_hash)
     task.set_request(taskrequest)
     return TaskRunner.run_single_task(task)
Example #3
0
 def getbestblockhash(self):
     task = Task(Config.BASEAPI_PATH + "/rpc/getbestblockhash.json")
     taskrequest = task.request()
     params = []
     taskrequest["params"] = params
     task.set_request(taskrequest)
     return TaskRunner.run_single_task(task)
Example #4
0
def invoke_function_commitDpos(nodeIndex=0,
                               sig_num=ADMIN_NUM,
                               sig_pubkeys=ADMIN_PUBLIST):
    request = {
        "NODE_INDEX": nodeIndex,
        "REQUEST": {
            "Qid": "t",
            "Method": "signativeinvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "address": "0700000000000000000000000000000000000000",
                "method": "commitDpos",
                "version": 0,
                "params": []
            }
        },
        "RESPONSE": {
            "error": 0
        }
    }

    return multi_contract(
        Task(name="invoke_function_commitDpos", ijson=request), sig_num,
        sig_pubkeys)
Example #5
0
 def getcontract(self, script_hash):
     task = Task(Config.BASEAPI_PATH + "/restful/get_contract_state.json")
     task.set_type("restful")
     taskrequest = task.request()
     taskrequest["api"] = "/api/v1/contract/" + str(script_hash)
     task.set_request(taskrequest)
     return TaskRunner.run_single_task(task)
Example #6
0
def balanceOf(contract_address, address, node_index=None, errorcode=47001):
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signeovminvoketx",
            "Params": {
                "gas_price":
                0,
                "gas_limit":
                1000000000,
                "address":
                contract_address,
                "version":
                1,
                "params": [{
                    "type": "string",
                    "value": "balanceOf"
                }, {
                    "type":
                    "array",
                    "value": [{
                        "type":
                        "bytearray",
                        "value":
                        script_hash_bl_reserver(base58_to_address(address))
                    }]
                }]
            }
        },
        "RESPONSE": {
            "error": errorcode
        },
        "NODE_INDEX": node_index
    }
    return call_contract(Task(name="balanceOf", ijson=request), twice=True)
Example #7
0
def invoke_function_vote(walletAddress,
                         voteList,
                         voteCount,
                         errorcode=0,
                         node_index=None):
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signativeinvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "address": "0700000000000000000000000000000000000000",
                "method": "voteForPeer",
                "version": 0,
                "params": [walletAddress, voteList, voteCount]
            }
        },
        "RESPONSE": {
            "error": errorcode
        }
    }
    if node_index != None:
        request["NODE_INDEX"] = node_index
    else:
        for node in Config.NODES:
            if node["address"] == walletAddress:
                request["NODE_INDEX"] = Config.NODES.index(node)
                break

    return call_contract(Task(name="invoke_function_vote", ijson=request),
                         twice=True)
Example #8
0
def invoke_function_test(contract_address, function_str, argvs = [{"type": "string","value": ""}], node_index = None):
	request = {
		"REQUEST": {
			"Qid": "t",
			"Method": "signeovminvoketx",
			"Params": {
				"gas_price": 0,
				"gas_limit": 1000000000,
				"address": contract_address,
				"version": 1,
				"params": [
					{
						"type": "string",
						"value": function_str
					},
					{
						"type": "array",
						"value": argvs
	 				}
				]
			}
		},
		"RESPONSE":{"error" : 0}
	}
		
	return call_contract(Task(name="invoke_function_test", ijson=request), twice = True)
Example #9
0
def invoke_function_update(func_,param0,param1,param2,param3,param4,param5,param6,param7,errorcode=47001):
	if(func_=="updateConfig"):
		filename="vbftConfig"
	else:
		filename="globalParam"
	getStorageConf(filename)
	request = {
		"REQUEST": {
			"Qid": "t",
			"Method": "signativeinvoketx",
			"Params": {
				"gas_price": 0,
				"gas_limit": 1000000000,
				"address": "0700000000000000000000000000000000000000",
				"method": func_,
				"version": 0,
				"params": [
							param0,
							param1,
							param2,
							param3,
							param4,
							param5,
							param6,
							param7
						  ]
					}
				},
		"RESPONSE":{"error" : errorcode}
	}
	(result,response)=	multi_contract(Task(name="invoke_function_update", ijson=request),Common.AdminNum,Common.AdminPublicKeyList)
	time.sleep(5)
	getStorageConf(filename)
	return (result,response)
Example #10
0
def bind_user_role(contract_address, admin_address, role_str, ontIDs, public_key="1", node_index = None):
	request = {
		"REQUEST": {
			"Qid": "t",
			"Method": "signativeinvoketx",
			"Params": {
				"gas_price": 0,
				"gas_limit": 1000000000,
				"address": "0600000000000000000000000000000000000000",
				"method": "assignOntIDsToRole",
				"version": 0,
				"params": [
					contract_address,
					admin_address,
					role_str,
					ontIDs,
					public_key
				]
			}
		},
		"RESPONSE":{"error" : 0}
	}

	if node_index != None:
		request["NODE_INDEX"] = node_index
	else:
		node_index = Common.ontid_map[admin_address]
		request["NODE_INDEX"] = node_index
		
	return call_contract(Task(name="bind_user_role", ijson=request), twice = True)
Example #11
0
def withdraw_user_role(contract_address, call_user, delegate_user, delegate_role, public_key="1", node_index = None):
	request = {
		"REQUEST": {
			"Qid": "t",
			"Method": "signativeinvoketx",
			"Params": {
				"gas_price": 0,
				"gas_limit": 1000000000,
				"address": "0600000000000000000000000000000000000000",
				"method": "withdraw",
				"version": 0,
				"params": [
					contract_address,
					call_user,
					delegate_user,
					delegate_role,
					public_key
				]
			}
		},
		"RESPONSE":{"error" : 0}
	}

	if node_index != None:
		request["NODE_INDEX"] = node_index
	else:
		node_index = Common.ontid_map[call_user]
		request["NODE_INDEX"] = node_index
		
	return call_contract(Task(name="withdraw_user_role", ijson=request), twice = True)
Example #12
0
def invoke_function_TransferPenalty(func_,
                                    pubKey,
                                    walletAddress,
                                    errorcode=47001):
    request = {
        "NODE_INDEX": 0,
        "REQUEST": {
            "Qid": "t",
            "Method": "signativeinvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "address": "0700000000000000000000000000000000000000",
                "method": func_,
                "version": 0,
                "params": [pubKey, walletAddress]
            }
        },
        "RESPONSE": {
            "error": errorcode
        }
    }

    return multi_contract(
        Task(name="invoke_function_TransferPenalty", ijson=request),
        Common.AdminNum, Common.AdminPublicKeyList)
Example #13
0
def invoke_function_vote(func_,
                         walletAddress,
                         voteList,
                         voteCount,
                         errorcode=47001,
                         node_index=None):
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signativeinvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "address": "0700000000000000000000000000000000000000",
                "method": func_,
                "version": 0,
                "params": [walletAddress, voteList, voteCount]
            }
        },
        "RESPONSE": {
            "error": errorcode
        }
    }
    if node_index != None:
        request["NODE_INDEX"] = node_index
    return call_contract(Task(name="invoke_function_vote", ijson=request),
                         twice=True)
Example #14
0
def multi_contract(task, m, pubkeyArray):
    (result,
     response) = sign_transction(task)  #Task(name="multi", ijson=request))
    signed_tx = response["result"]["signed_tx"]
    request1 = {
        "REQUEST": {
            "qid": "1",
            "method": "sigmutilrawtx",
            "params": {
                "raw_tx": signed_tx,
                "m": m,
                "pub_keys": pubkeyArray
            }
        },
        "RESPONSE": {}
    }
    print(request1)
    request1["NODE_INDEX"] = task.node_index()
    (result,
     response) = sign_multi_transction(Task(name="multi", ijson=request1))
    print(response)
    signed_tx = response["result"]["signed_tx"]
    print(signed_tx)
    call_signed_contract(signed_tx, True)
    return call_signed_contract(signed_tx, False)
Example #15
0
def native_transfer_ong(pay_address,
                        get_address,
                        amount,
                        node_index=None,
                        errorcode=47001):
    _amount = int(amount) * 1000000000
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signativeinvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "address": "0200000000000000000000000000000000000000",
                "method": "transfer",
                "version": 1,
                "params": [[[pay_address, get_address,
                             str(_amount)]]]
            }
        },
        "RESPONSE": {
            "error": errorcode
        },
        "NODE_INDEX": node_index
    }
    return call_contract(Task(name="transfer", ijson=request), twice=True)
Example #16
0
def invoke_function_register(func_,pubKey,walletAddress,ontCount,ontID,user,errorcode = 47001):
	request = {
		"NODE_INDEX":7,
		"REQUEST": {
			"Qid": "t",
			"Method": "signativeinvoketx",
			"Params": {
				"gas_price": 0,
				"gas_limit": 1000000000,
				"address": "0700000000000000000000000000000000000000",
				"method": func_,
				"version": 0,
				"params": [
							pubKey,
							walletAddress,
							ontCount,
							ontID,
							user
						  ]
					}
				},
		"RESPONSE":{"error" : errorcode}
	}
		
	return call_contract(Task(name="invoke_function_register", ijson=request), twice = True)
Example #17
0
def getMaxBlockChangeView():
    getbalance = Task("../utils/api/requests/rpc/getstorage.json")
    contract_address = "0200000000000000000000000000000000000000"
    key = "79626674436f6e666967"
    getbalance.data()["REQUEST"]["params"] = [contract_address, key]
    (result, response) = run_single_task(getbalance, True, False)
    return int(response["result"]["ont"])
Example #18
0
def native_transfer_multi(pay_address,get_address,amount, node_index = None,errorcode=47001):
	amount=amount*1000000000
	request = {
		"REQUEST": {
			"Qid": "t",
			"Method": "signativeinvoketx",
			"Params": {
				"gas_price": 0,
				"gas_limit": 1000000000,
				"address": "0100000000000000000000000000000000000000",
				"method": "transfer",
				"version": 1,
				"params": [[
					pay_address,
					get_address,
					str(amount)
				]]
			}
		},
		"RESPONSE":{"error" : errorcode},
	}
	return call_contract(Task(name="transfer", ijson=request), twice = True)
#InResponse={}
#getStorageVoteInfo(Config.NODES[0]["pubkey"],Config.NODES[7]["address"])
#getStorageVoteInfo(Config.NODES[0]["pubkey"],Config.NODES[7]["address"])
#nodeCountCheck(InResponse,7)
#getStorageConf("vbftConfig")
#getStorageConf("globalParam")
#getStorageConf("splitCurve")
Example #19
0
def allowance1(contract_address,
               pay_address,
               get_address,
               node_index=None,
               errorcode=47001,
               errorkey="error"):
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signativeinvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "address": "0200000000000000000000000000000000000000",
                "method": "allowance",
                "version": 1,
                "params": [pay_address, get_address]
            }
        },
        "RESPONSE": {
            "error": errorcode
        },
        "NODE_INDEX": node_index
    }
    if (errorkey == "error_code"):
        request["SIGN_RESPONSE"] = {errorkey: errorcode}

    return call_contract(Task(name="allowance", ijson=request), twice=True)
Example #20
0
    def test_004(self):
        priceTest = 366780

        log_path = "test_004.log"
        task_name = "test_004"

        self.start(log_path)
        (result1, response) = rpcapiTest.getbalance(address)

        print(result1)
        print(response["result"])
        ong1 = int(response["result"]["ong"])
        ont1 = response["result"]["ont"]
        task = Task(filterfile)
        (result, response) = call_contract(task, pre=False)

        (result1, response) = rpcapiTest.getbalance(address)
        ong2 = int(response["result"]["ong"])
        ont2 = response["result"]["ont"]

        print(ong1 - ong2 == (priceTest))
        print(priceTest)
        print(ong1 - ong2)

        if (ong1 - ong2 == (priceTest)):
            result = True
        else:
            result = False
        #print(ong,ont)
        self.finish(task_name, log_path, result, "")
Example #21
0
def invoke_function_register(pubKey,
                             walletAddress,
                             ontCount,
                             ontID,
                             user,
                             node_index=None):
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signativeinvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "address": "0700000000000000000000000000000000000000",
                "method": "registerCandidate",
                "version": 0,
                "params": [pubKey, walletAddress, ontCount, ontID, user]
            }
        },
        "RESPONSE": {
            "error": 0
        }
    }

    if node_index != None:
        request["NODE_INDEX"] = node_index
    else:
        node_index = Config.ontid_map[ontID]
        request["NODE_INDEX"] = node_index

    return call_contract(Task(name="invoke_function_register", ijson=request),
                         twice=True)
Example #22
0
def invoke_func_with_0_param(contract_address, func_name, node_index = None):
    request = {
        "DEPLOY" : False,
        "CODE_PATH" : "tasks/neo.neo",
        "REQUEST": {
            "Qid": "t",
            "Method": "signeovminvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "address": contract_address,
                "version": 0,
                "params": [
                    {
                        "type": "string",
                        "value": func_name
                    },
                    {
                        "type": "array",
                        "value": [{
                            "type": "string",
                            "value": ""
                        }]
                    }
                ]
            }
        },
        "RESPONSE": {}
    }
    
    return call_contract(Task(name="init_admin", ijson=request), twice = True)
Example #23
0
 def getbalance(self, addr):
     task = Task(Config.BASEAPI_PATH + "/restful/get_balance.json")
     task.set_type("restful")
     taskrequest = task.request()
     taskrequest["api"] = "/api/v1/balance/" + str(addr)
     task.set_request(taskrequest)
     return TaskRunner.run_single_task(task)
Example #24
0
def get_block(contract_address, block_hash, node_index = None):
    request = {
        "DEPLOY" : True,
        "CODE_PATH" : "tasks/neo.neo",
        "REQUEST": {
            "Qid": "t",
            "Method": "signeovminvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "address": contract_address,
                "version": 0,
                "params": [
                    {
                        "type": "string",
                        "value": "GetBlock"
                    },
                    {
                        "type": "array",
                        "value": [{
                            "type": "bytearray",
                            "value": block_hash
                        }]
                    }
                ]
            }
        },
        "RESPONSE": {}
    }
    
    return call_contract(Task(name="init_admin", ijson=request), twice = True)
Example #25
0
 def getsmartcodeeventbyhash(self, txhash):
     task = Task(Config.BASEAPI_PATH + "/restful/get_smtcode_evts.json")
     task.set_type("restful")
     taskrequest = task.request()
     taskrequest["api"] = "/api/v1/smartcode/event/txhash/" + str(txhash)
     task.set_request(taskrequest)
     return TaskRunner.run_single_task(task)
Example #26
0
def invoke_function_update(func_, param0, param1, param2, param3, param4,
                           param5, param6, param7):
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signativeinvoketx",
            "Params": {
                "gas_price":
                0,
                "gas_limit":
                1000000000,
                "address":
                "0700000000000000000000000000000000000000",
                "method":
                func_,
                "version":
                0,
                "params": [
                    param0, param1, param2, param3, param4, param5, param6,
                    param7
                ]
            }
        },
        "RESPONSE": {
            "error": 0
        }
    }
    (result, response) = multi_contract(
        Task(name="invoke_function_update", ijson=request), Common.AdminNum,
        Common.AdminPublicKeyList)
    time.sleep(5)
    return (result, response)
Example #27
0
def getKeyState(ontId,
                keyNum,
                public_key,
                node_index=None,
                errorcode=47001,
                resultStr=""):
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signativeinvoketx",
            "Params": {
                "gas_price": 0,
                "gas_limit": 1000000000,
                "method": "getKeyState",
                "address": "0300000000000000000000000000000000000000",
                "version": 1,
                "params": [ontId, keyNum]
            }
        },
        "RESPONSE": {
            "error": errorcode,
            "result": {
                "Result": ByteToHex(resultStr.encode("utf-8"))
            }
        }
    }

    if node_index != None:
        request["NODE_INDEX"] = node_index
    else:
        node_index = Common.ontid_map[public_key]
        request["NODE_INDEX"] = node_index

    return call_contract(Task(name="getKeyState", ijson=request), twice=True)
Example #28
0
def forNeo(contract_address,
           functionName,
           params,
           public_key,
           node_index=None,
           recovery_address_Array=[]):
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signeovminvoketx",
            "Params": {
                "gas_price":
                0,
                "gas_limit":
                1000000000,
                "address":
                contract_address,
                "version":
                1,
                "params": [{
                    "type": "string",
                    "value": functionName
                }, {
                    "type": "array",
                    "value": params
                }]
            }
        },
        "RESPONSE": {
            "error": 0
        }
    }

    if node_index != None:
        request["NODE_INDEX"] = node_index
    else:
        node_index = Config.ontid_map[public_key]
        request["NODE_INDEX"] = node_index

    if functionName == "changeRecovery":
        return API.contract().call_multisig_contract(
            Task(name="forNeo", ijson=request), recovery_address_Array[0],
            recovery_address_Array[1])
    else:
        return API.contract().call_contract(Task(name="forNeo", ijson=request),
                                            twice=True,
                                            sleep=2)
Example #29
0
    def invoke_function(self,
                        contract_address,
                        function_str,
                        callerOntID,
                        public_key="1",
                        argvs=[{
                            "type": "string",
                            "value": ""
                        }],
                        node_index=None,
                        sleep=5,
                        check_state=True):
        request = {
            "REQUEST": {
                "Qid": "t",
                "Method": "signeovminvoketx",
                "Params": {
                    "gas_price":
                    0,
                    "gas_limit":
                    1000000000,
                    "address":
                    contract_address,
                    "version":
                    1,
                    "params": [{
                        "type": "string",
                        "value": function_str
                    }, {
                        "type":
                        "array",
                        "value": [{
                            "type": "bytearray",
                            "value": callerOntID
                        }, {
                            "type": "int",
                            "value": public_key
                        }]
                    }, {
                        "type": "array",
                        "value": argvs
                    }]
                }
            },
            "RESPONSE": {
                "error": 0
            }
        }

        if node_index != None:
            request["NODE_INDEX"] = node_index
        else:
            node_index = Config.ontid_map[callerOntID]
            request["NODE_INDEX"] = node_index

        return self.call_contract(Task(name="invoke_function", ijson=request),
                                  twice=True,
                                  sleep=sleep,
                                  check_state=check_state)
Example #30
0
def transferFrom(contract_address,
                 sender,
                 pay_address,
                 get_address,
                 amount,
                 node_index=None,
                 senderType=False,
                 errorcode=47001,
                 errorkey="error"):
    if not senderType:
        sender = script_hash_bl_reserver(base58_to_address(sender))
        getaddress = sender
    else:
        getaddress = script_hash_bl_reserver(base58_to_address(get_address))
    request = {
        "REQUEST": {
            "Qid": "t",
            "Method": "signeovminvoketx",
            "Params": {
                "gas_price":
                0,
                "gas_limit":
                1000000000,
                "address":
                contract_address,
                "version":
                1,
                "params": [{
                    "type": "string",
                    "value": "transferFrom"
                }, {
                    "type":
                    "array",
                    "value": [{
                        "type": "bytearray",
                        "value": sender
                    }, {
                        "type":
                        "bytearray",
                        "value":
                        script_hash_bl_reserver(base58_to_address(pay_address))
                    }, {
                        "type": "bytearray",
                        "value": getaddress
                    }, {
                        "type": "int",
                        "value": amount
                    }]
                }]
            }
        },
        "RESPONSE": {
            "error": errorcode
        },
        "NODE_INDEX": node_index
    }
    if (errorkey == "error_code"):
        request["SIGN_RESPONSE"] = {errorkey: errorcode}
    return call_contract(Task(name="transferFrom", ijson=request), twice=True)