@@ -45,49 +45,41 @@ def read_state_endpoint(self, canister_id, data):
45
45
result = self .client .read_state (canister_id , data )
46
46
return result
47
47
48
- def query_raw (self , canister_id , method_name , * arg ):
49
- assert len (arg ) == 1 or len (arg ) == 2
48
+ def query_raw (self , canister_id , method_name , arg , return_type = None , effective_canister_id = None ):
50
49
req = {
51
50
'request_type' : "query" ,
52
51
'sender' : self .identity .sender ().bytes ,
53
52
'canister_id' : Principal .from_str (canister_id ).bytes if isinstance (canister_id , str ) else canister_id .bytes ,
54
53
'method_name' : method_name ,
55
- 'arg' : arg [ 0 ] ,
54
+ 'arg' : arg ,
56
55
'ingress_expiry' : self .get_expiry_date ()
57
56
}
58
57
_ , data = sign_request (req , self .identity )
59
- result = self .query_endpoint (canister_id , data )
58
+ result = self .query_endpoint (canister_id if effective_canister_id is None else effective_canister_id , data )
60
59
if result ['status' ] == 'replied' :
61
- if len (arg ) == 1 :
62
- res = decode (result ['reply' ]['arg' ])
63
- else :
64
- res = decode (result ['reply' ]['arg' ], arg [1 ])
65
- return res
60
+ return decode (result ['reply' ]['arg' ], return_type )
66
61
elif result ['status' ] == 'rejected' :
67
62
return result ['reject_message' ]
68
63
69
- def update_raw (self , canister_id , method_name , * arg , ** kwargs ):
70
- assert len (arg ) == 1 or len (arg ) == 2
64
+ def update_raw (self , canister_id , method_name , arg , return_type = None , effective_canister_id = None , ** kwargs ):
71
65
req = {
72
66
'request_type' : "call" ,
73
67
'sender' : self .identity .sender ().bytes ,
74
68
'canister_id' : Principal .from_str (canister_id ).bytes if isinstance (canister_id , str ) else canister_id .bytes ,
75
69
'method_name' : method_name ,
76
- 'arg' : arg [ 0 ] ,
70
+ 'arg' : arg ,
77
71
'ingress_expiry' : self .get_expiry_date ()
78
72
}
79
73
req_id , data = sign_request (req , self .identity )
80
- _ = self .call_endpoint (canister_id , req_id , data )
74
+ eid = canister_id if effective_canister_id is None else effective_canister_id
75
+ _ = self .call_endpoint (eid , req_id , data )
81
76
# print('update.req_id:', req_id.hex())
82
- status , result = self .poll (canister_id , req_id , ** kwargs )
77
+ status , result = self .poll (eid , req_id , ** kwargs )
83
78
if status != 'replied' :
84
- return status
79
+ return status
85
80
else :
86
- if len (arg ) == 1 :
87
- res = decode (result )
88
- else :
89
- res = decode (result , arg [1 ])
90
- return res
81
+ return decode (result , return_type )
82
+
91
83
92
84
93
85
def read_state_raw (self , canister_id , paths ):
0 commit comments