Skip to content

Commit b457544

Browse files
committed
runtime: Rename box.getProfile to box.profile
1 parent 6c475da commit b457544

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

core/src/three_box.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl ThreeBoxAdapter {
2525
#[async_trait]
2626
impl ThreeBoxAdapterTrait for ThreeBoxAdapter {
2727
// See https://github.com/3box/3box-js/blob/510137adbdf3ef4e240d9a7789946e967a19ff30/src/api.js#L160
28-
async fn get_profile(
28+
async fn profile(
2929
&self,
3030
address: &str,
3131
) -> Result<serde_json::Map<String, serde_json::Value>, Error> {

graph/src/components/three_box.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use failure::Error;
33

44
#[async_trait]
55
pub trait ThreeBoxAdapter: Send + Sync {
6-
async fn get_profile(
6+
async fn profile(
77
&self,
88
address: &str,
99
) -> Result<serde_json::Map<String, serde_json::Value>, Error>;

runtime/wasm/src/host_exports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,11 @@ impl HostExports {
659659
block_on03(self.arweave_adapter.tx_data(tx_id)).ok()
660660
}
661661

662-
pub(crate) fn box_get_profile(
662+
pub(crate) fn box_profile(
663663
&self,
664664
address: &str,
665665
) -> Option<serde_json::Map<String, serde_json::Value>> {
666-
block_on03(self.three_box_adapter.get_profile(address)).ok()
666+
block_on03(self.three_box_adapter.profile(address)).ok()
667667
}
668668
}
669669

runtime/wasm/src/module/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -994,13 +994,10 @@ impl WasmiModule {
994994
.or(Some(RuntimeValue::from(0))))
995995
}
996996

997-
/// function getProfile(address: string): JSONValue | null
998-
fn box_get_profile(
999-
&mut self,
1000-
address: AscPtr<AscString>,
1001-
) -> Result<Option<RuntimeValue>, Trap> {
997+
/// function profile(address: string): JSONValue | null
998+
fn box_profile(&mut self, address: AscPtr<AscString>) -> Result<Option<RuntimeValue>, Trap> {
1002999
let address: String = self.asc_get(address);
1003-
let profile = self.ctx.host_exports.box_get_profile(&address);
1000+
let profile = self.ctx.host_exports.box_profile(&address);
10041001
Ok(profile
10051002
.map(|profile| RuntimeValue::from(self.asc_new(&profile)))
10061003
.or(Some(RuntimeValue::from(0))))
@@ -1126,7 +1123,7 @@ impl Externals for WasmiModule {
11261123
DATA_SOURCE_CONTEXT => self.data_source_context(),
11271124
JSON_TRY_FROM_BYTES_FUNC_INDEX => self.json_try_from_bytes(args.nth_checked(0)?),
11281125
ARWEAVE_TRANSACTION_DATA => self.arweave_transaction_data(args.nth_checked(0)?),
1129-
BOX_PROFILE => self.box_get_profile(args.nth_checked(0)?),
1126+
BOX_PROFILE => self.box_profile(args.nth_checked(0)?),
11301127
_ => panic!("Unimplemented function at {}", index),
11311128
};
11321129
// Record execution time
@@ -1251,7 +1248,7 @@ impl ModuleImportResolver for ModuleResolver {
12511248
"arweave.transactionData" => {
12521249
FuncInstance::alloc_host(signature, ARWEAVE_TRANSACTION_DATA)
12531250
}
1254-
"box.getProfile" => FuncInstance::alloc_host(signature, BOX_PROFILE),
1251+
"box.profile" => FuncInstance::alloc_host(signature, BOX_PROFILE),
12551252

12561253
// Unknown export
12571254
_ => {
Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
1-
import { arweave, box, json, Bytes, JSONValue, TypedMap } from "@graphprotocol/graph-ts";
1+
import {
2+
arweave,
3+
box,
4+
json,
5+
Bytes,
6+
JSONValue,
7+
TypedMap,
8+
} from "@graphprotocol/graph-ts";
29
import { Trigger } from "../generated/Contract/Contract";
310

411
export function handleTrigger(event: Trigger): void {
5-
let data = json.fromBytes(arweave.transactionData("W2czhcswOAe4TgL4Q8kHHqoZ1jbFBntUCrtamYX_rOU") as Bytes)
6-
assert(data.toArray()[0].toString() == "Weather data for Dallas")
12+
let data = json.fromBytes(
13+
arweave.transactionData(
14+
"W2czhcswOAe4TgL4Q8kHHqoZ1jbFBntUCrtamYX_rOU"
15+
) as Bytes
16+
);
17+
assert(data.toArray()[0].toString() == "Weather data for Dallas");
718

8-
let no_data = arweave.transactionData("W2czhcswOAe4TgL4Q8kHHqoZ1jbFBntUCrtamYX_ZZZ")
9-
assert(no_data === null)
19+
let no_data = arweave.transactionData(
20+
"W2czhcswOAe4TgL4Q8kHHqoZ1jbFBntUCrtamYX_ZZZ"
21+
);
22+
assert(no_data === null);
1023

11-
let moo_master = box.getProfile("0xc8d807011058fcc0FB717dcd549b9ced09b53404") as TypedMap<string, JSONValue>
12-
assert(moo_master.get("name").toString() == "Moo Master")
24+
let moo_master = box.profile(
25+
"0xc8d807011058fcc0FB717dcd549b9ced09b53404"
26+
) as TypedMap<string, JSONValue>;
27+
assert(moo_master.get("name").toString() == "Moo Master");
1328

14-
let monkey_spirit = box.getProfile("did:3:bafyreia7db37k7epoc4qaifound6hk7swpwfkhudvdug4bgccjw6dh77ue") as TypedMap<string, JSONValue>
15-
assert(monkey_spirit.get("emoji").toString() == "🐵")
29+
let monkey_spirit = box.profile(
30+
"did:3:bafyreia7db37k7epoc4qaifound6hk7swpwfkhudvdug4bgccjw6dh77ue"
31+
) as TypedMap<string, JSONValue>;
32+
assert(monkey_spirit.get("emoji").toString() == "🐵");
1633

17-
let nothing = box.getProfile("0xc33307011058fcc0FB717dcd549b9ced09b53333")
18-
assert(nothing === null)
34+
let nothing = box.profile("0xc33307011058fcc0FB717dcd549b9ced09b53333");
35+
assert(nothing === null);
1936
}

0 commit comments

Comments
 (0)