Atomic swaps
In general, the scheme of atomic swaps in two independent blockchains looks as follows:
1
sequenceDiagram
2
participant Alice
3
participant Chain 1
4
participant Chain 2
5
participant Bob
6
Note over Alice: secret = 'random'
7
Note over Alice: hash = h(secret)
8
Alice ->> Chain 1: announces TX1(hash)
9
Note over Chain 1: TX1 waits for secret
10
Alice -->> Bob: tells hash
11
Bob ->> Chain 2: announces TX2(hash)
12
Note over Chain 2: TX2 waits for secret
13
Alice ->> Chain 2: announces TX3(secret, hash)
14
Note over Chain 2: TX2 executes
15
Note over Chain 2: secret becomes public
16
Note over Chain 2: Alice receives funds
17
Bob ->> Chain 1: announces TX4(secret, hash)
18
Note over Chain 1: TX1 executes
19
Note over Chain 1: Bob receives funds
Copied!

Transactions in Nimera Blockchain

  • BeginSwap - Begin exchange operation (signed by the sender)
    • sender - sender
    • target - recipient
    • timestamp - expiration time
    • alg - hashing algorithm
    • hash - hash
    • ?DATA (amount, color, etc) - data about the frozen funds
  • CommitSwap - complete the exchange operation (does not require a signature)
    • hash - hash of the secret as exchange operation identifier
    • secret - secret phrase
    • sender - exchange initiator
    • target - recipient
  • RollbackSwap - Roll back an exchange operation (does not require a signature)
    • hash - hash of the secret as exchange operation identifier
    • sender - exchange initiator
  • CancelSwap - Cancel the exchange operation (signed by the sender and recipient).
    • hash - hash of the secret as exchange operation identifier
    • sender - exchange initiator
    • target - recipient

How it works

Diagram of the asset flow within a single network:
1
graph TD
2
Alice((Alice)) -- BeginSwap --> swap
3
swap -- CancelSwap --> Alice
4
swap -- CommitSwap --> Bob((Bob))
5
swap -. time .-> expired_swap
6
expired_swap -- RollbackSwap --> Alice
7
8
expired_swap -- CancelSwap --> Alice
Copied!
BeginSwap initiates the exchange operation by freezing the funds in the sender's account. To do this, coins are deducted from the account and information about the operation (secret, lifetime, deducted amount, etc.) is being recorded in the account in a special field with unfinished exchanges.
CommitSwap unfreezes the funds and transfers them to the recipient. For this purpose, the secret, whose hash was specified earlier, is provided before the expiration of the exchange operation. In fact, the operation adds the transaction amount to the recipient's balance (it was deducted from the sender when the exchange was created), and then the information about the incomplete operation gets deleted from the sender's account.
CancelSwap cancels operations by mutual consent. It can be performed at any time, including before the exchange expires. This is an optional operation.
Last modified 10mo ago