mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-08 16:59:35 +08:00
fix a constraint bug in sqlite.rs, update clarity.rs to handle response types, update sample programs
This commit is contained in:
@@ -11,38 +11,41 @@
|
||||
(define-public (preorder
|
||||
(name-hash (buff 20))
|
||||
(name-price int))
|
||||
(if (contract-call! tokens token-transfer
|
||||
burn-address name-price)
|
||||
(insert-entry! preorder-map
|
||||
(if (is-ok? (contract-call! tokens token-transfer
|
||||
burn-address name-price))
|
||||
(begin (insert-entry! preorder-map
|
||||
(tuple (name-hash name-hash))
|
||||
(tuple (paid name-price)
|
||||
(buyer tx-sender)))
|
||||
'false))
|
||||
(ok 0))
|
||||
(err "token payment failed.")))
|
||||
|
||||
(define-public (register
|
||||
(recipient-principal principal)
|
||||
(name int)
|
||||
(salt int))
|
||||
(let ((preorder-entry
|
||||
(fetch-entry preorder-map
|
||||
(tuple (name-hash (hash160 (xor name salt))))))
|
||||
(expects! ;; name _must_ have been preordered.
|
||||
(fetch-entry preorder-map
|
||||
(tuple (name-hash (hash160 (xor name salt)))))
|
||||
(err "no preorder found")))
|
||||
(name-entry
|
||||
(fetch-entry name-map (tuple (name name)))))
|
||||
(if (and
|
||||
;; must be preordered
|
||||
(not (eq? preorder-entry 'null))
|
||||
;; name shouldn't *already* exist
|
||||
(eq? name-entry 'null)
|
||||
(is-none? name-entry)
|
||||
;; preorder must have paid enough
|
||||
(<= (price-function name)
|
||||
(get paid preorder-entry))
|
||||
;; preorder must have been the current principal
|
||||
(eq? tx-sender
|
||||
(get buyer preorder-entry)))
|
||||
(and
|
||||
(insert-entry! name-map
|
||||
(if (and
|
||||
(insert-entry! name-map
|
||||
(tuple (name name))
|
||||
(tuple (owner recipient-principal)))
|
||||
(delete-entry! preorder-map
|
||||
(delete-entry! preorder-map
|
||||
(tuple (name-hash (hash160 (xor name salt))))))
|
||||
'false)))
|
||||
(ok 0)
|
||||
(err "failed to insert new name entry"))
|
||||
(err "invalid name register"))))
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
(define-map tokens ((account principal)) ((balance int)))
|
||||
(define (get-balance (account principal))
|
||||
(let ((balance
|
||||
(get balance (fetch-entry tokens (tuple (account account))))))
|
||||
(if (eq? balance 'null) 0 balance)))
|
||||
(default-to 0 (get balance (fetch-entry tokens (tuple (account account))))))
|
||||
|
||||
(define (token-credit! (account principal) (tokens int))
|
||||
(if (<= tokens 0)
|
||||
'false
|
||||
(err "must move positive balance")
|
||||
(let ((current-amount (get-balance account)))
|
||||
(begin
|
||||
(set-entry! tokens (tuple (account account))
|
||||
(tuple (balance (+ tokens current-amount))))
|
||||
'true))))
|
||||
(ok tokens)))))
|
||||
|
||||
(define-public (token-transfer (to principal) (amount int))
|
||||
(let ((balance (get-balance tx-sender)))
|
||||
(if (or (> amount balance) (<= amount 0))
|
||||
'false
|
||||
(err "must transfer positive balance and possess funds")
|
||||
(begin
|
||||
(set-entry! tokens (tuple (account tx-sender))
|
||||
(tuple (balance (- balance amount))))
|
||||
@@ -23,10 +22,7 @@
|
||||
|
||||
(define-public (mint! (amount int))
|
||||
(let ((balance (get-balance tx-sender)))
|
||||
(begin (set-entry! tokens (tuple (account tx-sender))
|
||||
(tuple (balance (+ balance amount))))
|
||||
'true)))
|
||||
(token-credit! tx-sender amount)))
|
||||
|
||||
(begin (token-credit! 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR 10000)
|
||||
(token-credit! 'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G 300)
|
||||
'null)
|
||||
(token-credit! 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR 10000)
|
||||
(token-credit! 'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G 300)
|
||||
|
||||
@@ -409,12 +409,12 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) {
|
||||
};
|
||||
match result {
|
||||
Ok(x) => {
|
||||
if let Value::Bool(x) = x {
|
||||
if let Value::Response(data) = x {
|
||||
vm_env.commit();
|
||||
if x {
|
||||
println!("Transaction executed and committed.");
|
||||
if data.committed {
|
||||
println!("Transaction executed and committed. Returned: {}", data.data);
|
||||
} else {
|
||||
println!("Aborted: Transaction returned false.");
|
||||
println!("Aborted: {}", data.data);
|
||||
}
|
||||
} else {
|
||||
panic!(format!("Expected a bool result from transaction. Found: {}", x));
|
||||
|
||||
@@ -38,9 +38,10 @@ impl ContractDatabaseConnection {
|
||||
contract_db.execute("CREATE TABLE IF NOT EXISTS maps_table
|
||||
(map_identifier INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
contract_name TEXT NOT NULL,
|
||||
map_name TEXT UNIQUE NOT NULL,
|
||||
map_name TEXT NOT NULL,
|
||||
key_type TEXT NOT NULL,
|
||||
value_type TEXT NOT NULL)",
|
||||
value_type TEXT NOT NULL,
|
||||
UNIQUE(contract_name, map_name))",
|
||||
NO_PARAMS);
|
||||
contract_db.execute("CREATE TABLE IF NOT EXISTS data_table
|
||||
(data_identifier INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
||||
Reference in New Issue
Block a user