Skip to content

Commit

Permalink
pink-runtime: Add arg account to ocall::http_request
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Mar 8, 2023
1 parent 69c812c commit 541ba17
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions crates/phactory/src/contracts/pink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ impl OCalls for RuntimeHandle<'_> {
context::with(|ctx| ctx.chain_storage().pink_system_code().1)
}

fn http_request(&self, request: HttpRequest) -> Result<HttpResponse, HttpRequestError> {
fn http_request(
&self,
_contract: AccountId,
request: HttpRequest,
) -> Result<HttpResponse, HttpRequestError> {
pink_extension_runtime::http_request(request, context::time_remaining())
}
}
Expand Down Expand Up @@ -360,8 +364,12 @@ impl OCalls for RuntimeHandleMut<'_> {
self.readonly().latest_system_code()
}

fn http_request(&self, request: HttpRequest) -> Result<HttpResponse, HttpRequestError> {
self.readonly().http_request(request)
fn http_request(
&self,
contract: AccountId,
request: HttpRequest,
) -> Result<HttpResponse, HttpRequestError> {
self.readonly().http_request(contract, request)
}
}

Expand Down
6 changes: 5 additions & 1 deletion crates/pink/capi/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ pub mod ocall {
#[xcall(id = 13)]
fn latest_system_code(&self) -> Vec<u8>;
#[xcall(id = 14)]
fn http_request(&self, request: HttpRequest) -> Result<HttpResponse, HttpRequestError>;
fn http_request(
&self,
contracr: AccountId,
request: HttpRequest,
) -> Result<HttpResponse, HttpRequestError>;
}
}
6 changes: 5 additions & 1 deletion crates/pink/runner/tests/test_pink_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,11 @@ mod test_cluster {
vec![]
}

fn http_request(&self, request: HttpRequest) -> Result<HttpResponse, HttpRequestError> {
fn http_request(
&self,
_contract: AccountId,
request: HttpRequest,
) -> Result<HttpResponse, HttpRequestError> {
pink_extension_runtime::http_request(request, 10 * 1000)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pink/runtime/src/runtime/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl PinkExtBackend for CallInQuery {
type Error = DispatchError;
fn http_request(&self, request: HttpRequest) -> Result<HttpResponse, Self::Error> {
OCallImpl
.http_request(request)
.http_request(self.address.clone(), request)
.map_err(|err| DispatchError::Other(err.display()))
}

Expand Down

0 comments on commit 541ba17

Please sign in to comment.