Skip to content

Instantly share code, notes, and snippets.

@qiwihui
Created August 3, 2022 03:46
Show Gist options
  • Save qiwihui/eec0017befc08fd0dbd12a07ee9edad8 to your computer and use it in GitHub Desktop.
Save qiwihui/eec0017befc08fd0dbd12a07ee9edad8 to your computer and use it in GitHub Desktop.
Escrow.move
/// @title Escrow
/// @dev Basic escrow module: holds an object designated for a recipient until the sender approves withdrawal.
module SFC::Escrow {
use StarcoinFramework::Signer;
use StarcoinFramework::Option::{Self, Option};
struct Escrow<T: key + store> has key {
recipient: address,
obj: Option<T>
}
/// @dev Stores the sent object in an escrow object.
/// @param recipient The destination address of the escrowed object.
public entry fun escrow<T: key + store>(sender: &signer, recipient: address, obj_in: T) {
let escrow = Escrow<T> {
recipient,
obj: Option::some(obj_in)
};
move_to(sender, escrow);
}
/// @dev Transfers escrowed object to the recipient.
public entry fun transfer<T: key + store>(sender: &signer) acquires Escrow {
let escrow = move_from<Escrow<T>>(Signer::address_of(sender));
let Escrow {
recipient: recipient,
obj: obj,
} = escrow;
let t_escrow = borrow_global_mut<Escrow<T>>(recipient);
Option::fill(&mut t_escrow.obj, obj);
}
public entry fun accept<T: key + store>(recipient: &signer) {
move_to(recipient, Escrow<T> {
recipient: Signer::address_of(recipient),
obj: Option::none(),
});
}
}
@qiwihui
Copy link
Author

qiwihui commented Aug 3, 2022

Line 31 error:

Invalid call of '(StarcoinFramework=0x1)::Option::fill'. Invalid argument for parameter 'e'
Escrow.move(9, 14): Given: '(StarcoinFramework=0x1)::Option::Option<T>'
Escrow.move(30, 49): Expected: 'T'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment