SatoshiPortal / boltz-rust

Boltz client rust crate
https://docs.boltz.exchange
30 stars 16 forks source link

Recovery File #55

Open i5hi opened 1 week ago

i5hi commented 1 week ago

Code for recovery file for refunds for scripts are incomplete.

i5hi commented 6 days ago

@michael1011 @jackstar12 Please share any relevant notes / types for this.

i5hi commented 6 days ago

This is what we currently have:

// Boltz standard JSON refund swap file. Can be used to create a file that can be uploaded to boltz.exchange
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RefundSwapFile {
    pub id: String,
    pub currency: String,
    pub redeem_script: String,
    pub private_key: String,
    pub timeout_block_height: u32,
}
impl RefundSwapFile {
    pub fn file_name(&self) -> String {
        format!("boltz-{}.json", self.id)
    }
    pub fn write_to_file<P: AsRef<Path>>(&self, path: P) -> Result<(), Error> {
        let mut full_path = PathBuf::from(path.as_ref());
        full_path.push(self.file_name());
        let mut file = File::create(&full_path)?;
        let json = serde_json::to_string_pretty(self)?;
        writeln!(file, "{}", json)?;
        Ok(())
    }
    pub fn read_from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
        let mut file = File::open(path)?;
        let mut contents = String::new();
        file.read_to_string(&mut contents)?;
        Ok(serde_json::from_str(&contents)?)
    }
}
michael1011 commented 3 days ago

@i5hi that's what our refund files for the web app look like:

{
  "id": "SUk5ZpvByr7T",
  "address": "lq1pqgvpgdd3l8r9r5872u6807995c3tjvng29uva6d4wjpeasnqwwrut7l957w7ywwaypn5zp309x6klalrk552avv04mhvg8lrxc8h3qr7syyar9ar4g0e",
  "swapTree": {
    "claimLeaf": {
      "version": 196,
      "output": "a9148016aecb6c365862c758abc506b7237b016e2cc38820262003a199ebba1632920977a38b156171e1b423b453b32c8e267ddf53fedb8eac"
    },
    "refundLeaf": {
      "version": 196,
      "output": "20b6f5bf61251d25e625fc9b1a4fd8782616ceba3b229ad80556c7223e7388bbcead039ec62cb1"
    }
  },
  "blindingKey": "44d827dc1be2e27cc077160861e1f895d4a424f653c0192e2917c193fb64d173",
  "claimPublicKey": "03262003a199ebba1632920977a38b156171e1b423b453b32c8e267ddf53fedb8e",
  "timeoutBlockHeight": 2934430,
  "type": "submarine",
  "assetSend": "L-BTC",
  "assetReceive": "BTC",
  "date": 1719830282064,
  "version": 3,
  "sendAmount": 52315,
  "receiveAmount": 52248,
  "refundPrivateKey": "1ec2e1d1d3a2f2e489e884092b378ad51e2a2be9b9f804c7878ce58b7909f2e0"
}

blindingKey can be omitted for BTC swaps