forked from TBD54566975/tbdex-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Order Instructions to APID (TBD54566975#93)
* add orderinstructions * add OrderInstructionsData field * add order instructions * update * generate schemas * update bound/kt * lint * bindings * update pfi example * bump to 21 * Update docs/API_DESIGN.md Co-authored-by: Kendall Weihe <kendallweihe@gmail.com> --------- Co-authored-by: Kendall Weihe <kendallweihe@gmail.com>
- Loading branch information
1 parent
adfa9f9
commit c35f7aa
Showing
31 changed files
with
928 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ Cargo.lock | |
build/ | ||
.gradle/ | ||
**/.idea/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod cancel; | ||
pub mod close; | ||
pub mod order; | ||
pub mod order_instructions; | ||
pub mod order_status; | ||
pub mod quote; | ||
pub mod rfq; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::errors::{Result, TbdexSdkError}; | ||
use std::sync::{Arc, RwLock}; | ||
use tbdex::{ | ||
json::{FromJson, ToJson}, | ||
messages::order_instructions::{ | ||
OrderInstructions as InnerOrderInstructions, OrderInstructionsData, | ||
}, | ||
}; | ||
use web5_uniffi_wrapper::dids::bearer_did::BearerDid; | ||
|
||
pub struct OrderInstructions(pub Arc<RwLock<InnerOrderInstructions>>); | ||
|
||
impl OrderInstructions { | ||
pub fn create( | ||
to: String, | ||
from: String, | ||
exchange_id: String, | ||
data: OrderInstructionsData, | ||
protocol: Option<String>, | ||
external_id: Option<String>, | ||
) -> Result<Self> { | ||
let order_instructions = | ||
InnerOrderInstructions::create(&to, &from, &exchange_id, &data, protocol, external_id)?; | ||
|
||
Ok(Self(Arc::new(RwLock::new(order_instructions)))) | ||
} | ||
|
||
pub fn sign(&self, bearer_did: Arc<BearerDid>) -> Result<()> { | ||
let mut inner_order_instructions = self | ||
.0 | ||
.write() | ||
.map_err(|e| TbdexSdkError::from_poison_error(e, "RwLockWriteError"))?; | ||
inner_order_instructions.sign(&bearer_did.0.clone())?; | ||
Ok(()) | ||
} | ||
|
||
pub fn from_json_string(json: &str) -> Result<Self> { | ||
let inner_order_instructions = InnerOrderInstructions::from_json_string(json)?; | ||
|
||
Ok(Self(Arc::new(RwLock::new(inner_order_instructions)))) | ||
} | ||
|
||
pub fn to_json_string(&self) -> Result<String> { | ||
let inner_order_instructions = self | ||
.0 | ||
.read() | ||
.map_err(|e| TbdexSdkError::from_poison_error(e, "RwLockReadError"))?; | ||
|
||
Ok(inner_order_instructions.to_json_string()?) | ||
} | ||
|
||
pub fn get_data(&self) -> Result<InnerOrderInstructions> { | ||
let order_instructions = self | ||
.0 | ||
.read() | ||
.map_err(|e| TbdexSdkError::from_poison_error(e, "RwLockReadError"))?; | ||
|
||
Ok(order_instructions.clone()) | ||
} | ||
|
||
pub fn verify(&self) -> Result<()> { | ||
let order_instructions = self | ||
.0 | ||
.read() | ||
.map_err(|e| TbdexSdkError::from_poison_error(e, "RwLockReadError"))?; | ||
|
||
Ok(order_instructions.verify()?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
bound/kt/src/main/kotlin/tbdex/sdk/messages/OrderInstructions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package tbdex.sdk.messages | ||
|
||
import tbdex.sdk.http.ReplyToMessage | ||
import tbdex.sdk.rust.SystemArchitecture | ||
import tbdex.sdk.web5.BearerDid | ||
|
||
import tbdex.sdk.rust.OrderInstructionsDataData as RustCoreOrderInstructionsData | ||
typealias OrderInstructionsData = RustCoreOrderInstructionsData | ||
|
||
class OrderInstructions private constructor( | ||
val metadata: MessageMetadata, | ||
val data: OrderInstructionsData, | ||
val signature: String, | ||
internal val rustCoreOrderInstructions: tbdex.sdk.rust.OrderInstructions | ||
): Message, ReplyToMessage { | ||
init { | ||
SystemArchitecture.set() // ensure the sys arch is set for first-time loading | ||
} | ||
|
||
companion object { | ||
fun create( | ||
to: String, | ||
from: String, | ||
exchangeId: String, | ||
data: OrderInstructionsData, | ||
protocol: String? = null, | ||
externalId: String? = null | ||
): OrderInstructions { | ||
val rustCoreOrderInstructions = | ||
tbdex.sdk.rust.OrderInstructions.create(to, from, exchangeId, data, protocol, externalId) | ||
val rustCoreData = rustCoreOrderInstructions.getData() | ||
return OrderInstructions(rustCoreData.metadata, rustCoreData.data, rustCoreData.signature, rustCoreOrderInstructions) | ||
} | ||
|
||
fun fromJsonString(json: String): OrderInstructions { | ||
val rustCoreOrderInstructions = tbdex.sdk.rust.OrderInstructions.fromJsonString(json) | ||
val rustCoreData = rustCoreOrderInstructions.getData() | ||
return OrderInstructions(rustCoreData.metadata, rustCoreData.data, rustCoreData.signature, rustCoreOrderInstructions) | ||
} | ||
|
||
internal fun fromRustCoreOrderInstructions(rustCoreOrderInstructions: tbdex.sdk.rust.OrderInstructions): OrderInstructions { | ||
val rustCoreData = rustCoreOrderInstructions.getData() | ||
return OrderInstructions(rustCoreData.metadata, rustCoreData.data, rustCoreData.signature, rustCoreOrderInstructions) | ||
} | ||
} | ||
|
||
fun toJsonString(): String { | ||
return this.rustCoreOrderInstructions.toJsonString() | ||
} | ||
|
||
fun sign(bearerDid: BearerDid) { | ||
this.rustCoreOrderInstructions.sign(bearerDid.rustCoreBearerDid) | ||
} | ||
|
||
fun verify() { | ||
this.rustCoreOrderInstructions.verify() | ||
} | ||
} |
Oops, something went wrong.