Skip to content

Commit

Permalink
feat: return location when creating contract
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Gellis <simongellis@gmail.com>
  • Loading branch information
SupernaviX committed Feb 7, 2025
1 parent 1466d8d commit 37222d5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "operations"
ADD COLUMN "contract_address" TEXT NULL
2 changes: 2 additions & 0 deletions firefly-cardanoconnect/src/operations/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl OperationsManager {
id,
status: OperationStatus::Pending,
tx_id: None,
contract_address: Some(name.to_string()),
};
self.update_operation(&op).await?;
match self.contracts.deploy(name, contract).await {
Expand Down Expand Up @@ -71,6 +72,7 @@ impl OperationsManager {
id,
status: OperationStatus::Pending,
tx_id: None,
contract_address: None,
};
self.update_operation(&op).await?;
let result = self.contracts.invoke(contract, method, params).await;
Expand Down
1 change: 1 addition & 0 deletions firefly-cardanoconnect/src/operations/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Operation {
pub id: OperationId,
pub status: OperationStatus,
pub tx_id: Option<String>,
pub contract_address: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
12 changes: 8 additions & 4 deletions firefly-cardanoconnect/src/persistence/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,20 @@ impl Persistence for SqlitePersistence {
let status = op.status.name();
let error_message = op.status.error_message();
c.prepare_cached(
"INSERT INTO operations (id, status, error_message, tx_id)
VALUES (?1, ?2, ?3, ?4)
"INSERT INTO operations (id, status, error_message, tx_id, contract_address)
VALUES (?1, ?2, ?3, ?4, ?5)
ON CONFLICT(id) DO UPDATE SET
status=excluded.status,
error_message=excluded.error_message,
tx_id=excluded.tx_id",
tx_id=excluded.tx_id,
contract_address=excluded.contract_address",
)?
.execute(params![
op.id.to_string(),
status,
error_message,
op.tx_id,
op.contract_address,
])?;
Ok(())
})
Expand All @@ -345,7 +347,7 @@ impl Persistence for SqlitePersistence {
.call_unwrap(move |c| {
let Some(op) = c
.prepare_cached(
"SELECT id, status, error_message, tx_id
"SELECT id, status, error_message, tx_id, contract_address
FROM operations
WHERE id = ?1",
)?
Expand Down Expand Up @@ -437,10 +439,12 @@ fn parse_operation(row: &Row) -> Result<Operation> {
},
};
let tx_id: Option<String> = row.get("tx_id")?;
let contract_address: Option<String> = row.get("contract_address")?;
Ok(Operation {
id: id.into(),
status,
tx_id,
contract_address,
})
}

Expand Down
9 changes: 9 additions & 0 deletions firefly-cardanoconnect/src/routes/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ async fn send_operation(socket: &mut WebSocket, op: Operation) -> Result<()> {
},
transaction_hash: op.tx_id.clone(),
error_message: op.status.error_message().map(|m| m.to_string()),
contract_location: op
.contract_address
.map(|address| ContractLocation { address }),
};
let outgoing_json = serde_json::to_string(&operation)?;
socket.send(Message::Text(outgoing_json.into())).await?;
Expand Down Expand Up @@ -195,6 +198,7 @@ struct OutgoingOperation {
headers: OperationHeaders,
transaction_hash: Option<String>,
error_message: Option<String>,
contract_location: Option<ContractLocation>,
}

#[derive(Debug, Serialize)]
Expand All @@ -205,6 +209,11 @@ struct OperationHeaders {
type_: String,
}

#[derive(Debug, Serialize)]
struct ContractLocation {
address: String,
}

pub async fn handle_socket_upgrade(
State(app_state): State<AppState>,
ws: WebSocketUpgrade,
Expand Down

0 comments on commit 37222d5

Please sign in to comment.