Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proto/fkms/v1/signer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ message FlowSignerPayload {
string block_id = 3;
uint32 key_index = 4;
uint64 sequence = 5;
bytes script = 6;
string contract_address = 6;
}

message SorobanSignerPayload {
Expand Down
26 changes: 26 additions & 0 deletions src/codec/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ use sha3::{Digest, Sha3_256};
const FLOW_TRANSACTION_DOMAIN_TAG: &[u8] =
b"FLOW-V0.0-transaction\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";

const RELAY_SCRIPT_TEMPLATE: &str = r#"
import BandOracle from {contract}

transaction (symbolsRates: {String: UInt64}, resolveTime: UInt64, requestID: UInt64) {
let relayRef: &BandOracle.Relay

prepare (acct: auth(BorrowValue)&Account){
// Get a reference to the relayer resource from storage
self.relayRef = acct.storage.borrow<&BandOracle.Relay>(from: BandOracle.RelayStoragePath) ??
panic("Cannot borrow reference to relay resource")
}

execute {
// Call the relayRates function exposed by the relayer resource
self.relayRef.relayRates(symbolsRates: symbolsRates, resolveTime: resolveTime, requestID: requestID)
}
}
"#;

/// Builds the Cadence relay script with the given contract address substituted in.
pub fn build_script(contract_address: &str) -> Vec<u8> {
RELAY_SCRIPT_TEMPLATE
.replace("{contract}", contract_address)
.into_bytes()
}

// Builds the RLP-encoded transaction payload used for signing.
#[allow(clippy::too_many_arguments)]
pub fn build_payload_rlp(
Expand Down
3 changes: 2 additions & 1 deletion src/server/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,15 @@ impl FkmsService for Server {
.map_err(|_| Status::invalid_argument("Timestamp must be non-negative"))?;
let request_id = tunnel_packet.sequence;

let script = flow::build_script(&signer_payload.contract_address);
let payload_rlp = flow::build_payload_rlp(
&signals,
&signer_payload.address,
signer_payload.compute_limit,
&signer_payload.block_id,
signer_payload.key_index,
signer_payload.sequence,
&signer_payload.script,
&script,
resolve_time,
request_id,
)
Expand Down
Loading