Skip to content

Commit 763c80f

Browse files
committed
Merge branch 'develop' into feature/blocks-transactions-accounts
2 parents 214841b + 8c09828 commit 763c80f

File tree

33 files changed

+1428
-719
lines changed

33 files changed

+1428
-719
lines changed

Diff for: circle.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jobs:
33
deploy:
44
working_directory: /build
55
docker:
6-
- image: rust:1.39.0-stretch
6+
- image: rust:1.39-stretch
77
steps:
88
- checkout
99
- run:
@@ -15,7 +15,7 @@ jobs:
1515
test_demo:
1616
working_directory: /test
1717
docker:
18-
- image: rust:1.39.0-stretch
18+
- image: rust:1.39-stretch
1919
steps:
2020
- checkout
2121
- run:

Diff for: rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.39.0
1+
stable

Diff for: sample-programs/names.clar

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
(define-public (preorder
1212
(name-hash (buff 20))
1313
(name-price uint))
14-
(if (is-ok? (contract-call! .tokens token-transfer
14+
(if (is-ok (contract-call? .tokens token-transfer
1515
burn-address name-price))
16-
(begin (map-insert! preorder-map
16+
(begin (map-insert preorder-map
1717
(tuple (name-hash name-hash))
1818
(tuple (paid name-price)
1919
(buyer tx-sender)))
@@ -25,26 +25,26 @@
2525
(name uint)
2626
(salt uint))
2727
(let ((preorder-entry
28-
(expects! ;; name _must_ have been preordered.
29-
(map-get preorder-map
28+
(unwrap! ;; name _must_ have been preordered.
29+
(map-get? preorder-map
3030
(tuple (name-hash (hash160 (xor name salt)))))
3131
(err "no preorder found")))
3232
(name-entry
33-
(map-get name-map (tuple (name name)))))
33+
(map-get? name-map (tuple (name name)))))
3434
(if (and
3535
;; name shouldn't *already* exist
36-
(is-none? name-entry)
36+
(is-none name-entry)
3737
;; preorder must have paid enough
3838
(<= (price-function name)
3939
(get paid preorder-entry))
4040
;; preorder must have been the current principal
41-
(eq? tx-sender
41+
(is-eq tx-sender
4242
(get buyer preorder-entry)))
4343
(if (and
44-
(map-insert! name-map
44+
(map-insert name-map
4545
(tuple (name name))
4646
(tuple (owner recipient-principal)))
47-
(map-delete! preorder-map
47+
(map-delete preorder-map
4848
(tuple (name-hash (hash160 (xor name salt))))))
4949
(ok u0)
5050
(err "failed to insert new name entry"))

Diff for: sample-programs/tokens.clar

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
(define-map tokens ((account principal)) ((balance uint)))
22
(define-private (get-balance (account principal))
3-
(default-to u0 (get balance (map-get tokens (tuple (account account))))))
3+
(default-to u0 (get balance (map-get? tokens (tuple (account account))))))
44

55
(define-private (token-credit! (account principal) (amount uint))
66
(if (<= amount u0)
77
(err "must move positive balance")
88
(let ((current-amount (get-balance account)))
99
(begin
10-
(map-set! tokens (tuple (account account))
10+
(map-set tokens (tuple (account account))
1111
(tuple (balance (+ amount current-amount))))
1212
(ok amount)))))
1313

@@ -16,7 +16,7 @@
1616
(if (or (> amount balance) (<= amount u0))
1717
(err "must transfer positive balance and possess funds")
1818
(begin
19-
(map-set! tokens (tuple (account tx-sender))
19+
(map-set tokens (tuple (account tx-sender))
2020
(tuple (balance (- balance amount))))
2121
(token-credit! to amount)))))
2222

Diff for: src/vm/analysis/definition_sorter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl <'a> DefinitionSorter {
5757
let sorted_indexes = walker.get_sorted_dependencies(&self.graph)?;
5858

5959
if let Some(deps) = walker.get_cycling_dependencies(&self.graph, &sorted_indexes) {
60-
let deps_props: Vec<(_)> = deps.iter().map(|i| {
60+
let deps_props: Vec<_> = deps.iter().map(|i| {
6161
let exp = &contract_analysis.expressions[*i];
6262
self.find_expression_definition(&exp).unwrap()
6363
}).collect();

Diff for: src/vm/analysis/definition_sorter/tests.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn should_succeed_sorting_contract_case_1() {
2626
(kv-del key))
2727
(define-private (kv-del (key int))
2828
(begin
29-
(map-delete! kv-store ((key key)))
29+
(map-delete kv-store ((key key)))
3030
key))
3131
(define-map kv-store ((key int)) ((value int)))
3232
"#;
@@ -110,7 +110,7 @@ fn should_raise_dependency_cycle_case_get() {
110110
fn should_not_raise_dependency_cycle_case_fetch_entry() {
111111
let contract = r#"
112112
(define-private (foo (x int)) (begin (bar 1) 1))
113-
(define-private (bar (x int)) (map-get kv-store ((foo 1))))
113+
(define-private (bar (x int)) (map-get? kv-store ((foo 1))))
114114
(define-map kv-store ((foo int)) ((bar int)))
115115
"#;
116116

@@ -122,7 +122,7 @@ fn should_not_raise_dependency_cycle_case_fetch_entry() {
122122
fn should_raise_dependency_cycle_case_fetch_entry() {
123123
let contract = r#"
124124
(define-private (foo (x int)) (+ (bar x) x))
125-
(define-private (bar (x int)) (map-get kv-store ((foo (foo 1)))))
125+
(define-private (bar (x int)) (map-get? kv-store ((foo (foo 1)))))
126126
(define-map kv-store ((foo int)) ((bar int)))
127127
"#;
128128

@@ -134,7 +134,7 @@ fn should_raise_dependency_cycle_case_fetch_entry() {
134134
fn should_not_raise_dependency_cycle_case_delete_entry() {
135135
let contract = r#"
136136
(define-private (foo (x int)) (begin (bar 1) 1))
137-
(define-private (bar (x int)) (map-delete! kv-store (tuple (foo 1))))
137+
(define-private (bar (x int)) (map-delete kv-store (tuple (foo 1))))
138138
(define-map kv-store ((foo int)) ((bar int)))
139139
"#;
140140

@@ -146,7 +146,7 @@ fn should_not_raise_dependency_cycle_case_delete_entry() {
146146
fn should_raise_dependency_cycle_case_delete_entry() {
147147
let contract = r#"
148148
(define-private (foo (x int)) (+ (bar x) x))
149-
(define-private (bar (x int)) (map-delete! kv-store (tuple (foo (foo 1)))))
149+
(define-private (bar (x int)) (map-delete kv-store (tuple (foo (foo 1)))))
150150
(define-map kv-store ((foo int)) ((bar int)))
151151
"#;
152152

@@ -158,7 +158,7 @@ fn should_raise_dependency_cycle_case_delete_entry() {
158158
fn should_not_raise_dependency_cycle_case_set_entry() {
159159
let contract = r#"
160160
(define-private (foo (x int)) (begin (bar 1) 1))
161-
(define-private (bar (x int)) (map-set! kv-store ((foo 1)) ((bar 3))))
161+
(define-private (bar (x int)) (map-set kv-store ((foo 1)) ((bar 3))))
162162
(define-map kv-store ((foo int)) ((bar int)))
163163
"#;
164164

@@ -170,7 +170,7 @@ fn should_not_raise_dependency_cycle_case_set_entry() {
170170
fn should_raise_dependency_cycle_case_set_entry() {
171171
let contract = r#"
172172
(define-private (foo (x int)) (+ (bar x) x))
173-
(define-private (bar (x int)) (map-set! kv-store ((foo 1)) ((bar (foo 1)))))
173+
(define-private (bar (x int)) (map-set kv-store ((foo 1)) ((bar (foo 1)))))
174174
(define-map kv-store ((foo int)) ((bar int)))
175175
"#;
176176

@@ -182,7 +182,7 @@ fn should_raise_dependency_cycle_case_set_entry() {
182182
fn should_not_raise_dependency_cycle_case_insert_entry() {
183183
let contract = r#"
184184
(define-private (foo (x int)) (begin (bar 1) 1))
185-
(define-private (bar (x int)) (map-insert! kv-store ((foo 1)) ((bar 3))))
185+
(define-private (bar (x int)) (map-insert kv-store ((foo 1)) ((bar 3))))
186186
(define-map kv-store ((foo int)) ((bar int)))
187187
"#;
188188

@@ -194,7 +194,7 @@ fn should_not_raise_dependency_cycle_case_insert_entry() {
194194
fn should_raise_dependency_cycle_case_insert_entry() {
195195
let contract = r#"
196196
(define-private (foo (x int)) (+ (bar x) x))
197-
(define-private (bar (x int)) (map-insert! kv-store ((foo (foo 1))) ((bar 3))))
197+
(define-private (bar (x int)) (map-insert kv-store ((foo (foo 1))) ((bar 3))))
198198
(define-map kv-store ((foo int)) ((bar int)))
199199
"#;
200200

@@ -206,7 +206,7 @@ fn should_raise_dependency_cycle_case_insert_entry() {
206206
fn should_not_raise_dependency_cycle_case_fetch_contract_entry() {
207207
let contract = r#"
208208
(define-private (foo (x int)) (begin (bar 1) 1))
209-
(define-private (bar (x int)) (contract-map-get .contract1 kv-store ((foo 1))))
209+
(define-private (bar (x int)) (contract-map-get? .contract1 kv-store ((foo 1))))
210210
"#;
211211

212212
run_scoped_analysis_helper(contract).unwrap();
@@ -216,7 +216,7 @@ fn should_not_raise_dependency_cycle_case_fetch_contract_entry() {
216216
fn should_raise_dependency_cycle_case_fetch_contract_entry() {
217217
let contract = r#"
218218
(define-private (foo (x int)) (+ (bar x) x))
219-
(define-private (bar (x int)) (map-get kv-store ((foo (foo 1)))))
219+
(define-private (bar (x int)) (map-get? kv-store ((foo (foo 1)))))
220220
"#;
221221

222222
let err = run_scoped_analysis_helper(contract).unwrap_err();

Diff for: src/vm/analysis/errors.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ pub enum CheckErrors {
1414
ValueTooLarge,
1515
ExpectedName,
1616

17+
// match errors
18+
BadMatchOptionSyntax(Box<CheckErrors>),
19+
BadMatchResponseSyntax(Box<CheckErrors>),
20+
BadMatchInput(TypeSignature),
21+
1722
// list typing errors
1823
UnknownListConstructionFailure,
1924
ListTypesMustMatch,
@@ -34,11 +39,15 @@ pub enum CheckErrors {
3439

3540
ExpectedOptionalType(TypeSignature),
3641
ExpectedResponseType(TypeSignature),
42+
ExpectedOptionalOrResponseType(TypeSignature),
3743
ExpectedOptionalValue(Value),
3844
ExpectedResponseValue(Value),
45+
ExpectedOptionalOrResponseValue(Value),
3946
CouldNotDetermineResponseOkType,
4047
CouldNotDetermineResponseErrType,
4148

49+
CouldNotDetermineMatchTypes,
50+
4251
// Checker runtime failures
4352
TypeAlreadyAnnotatedFailure,
4453
TypeAnnotationExpectedFailure,
@@ -86,7 +95,7 @@ pub enum CheckErrors {
8695
ContractAlreadyExists(String),
8796
ContractCallExpectName,
8897

89-
// get-block-info errors
98+
// get-block-info? errors
9099
NoSuchBlockInfoProperty(String),
91100
GetBlockInfoExpectPropertyName,
92101

@@ -113,6 +122,7 @@ pub enum CheckErrors {
113122
RequiresAtLeastArguments(usize, usize),
114123
IncorrectArgumentCount(usize, usize),
115124
IfArmsMustMatch(TypeSignature, TypeSignature),
125+
MatchArmsMustMatch(TypeSignature, TypeSignature),
116126
DefaultTypesMustMatch(TypeSignature, TypeSignature),
117127
TooManyExpressions,
118128
IllegalOrUnknownFunctionApplication(String),
@@ -215,6 +225,14 @@ impl DiagnosableError for CheckErrors {
215225

216226
fn message(&self) -> String {
217227
match &self {
228+
CheckErrors::BadMatchOptionSyntax(source) =>
229+
format!("match on a optional type uses the following syntax: (match input some-name if-some-expression if-none-expression). Caused by: {}",
230+
source.message()),
231+
CheckErrors::BadMatchResponseSyntax(source) =>
232+
format!("match on a result type uses the following syntax: (match input ok-name if-ok-expression err-name if-err-expression). Caused by: {}",
233+
source.message()),
234+
CheckErrors::BadMatchInput(t) =>
235+
format!("match requires an input of either a response or optional, found input: '{}'", t),
218236
CheckErrors::TypeAnnotationExpectedFailure => "analysis expected type to already be annotated for expression".into(),
219237
CheckErrors::CostOverflow => "contract execution cost overflowed cost counter".into(),
220238
CheckErrors::InvalidTypeDescription => "supplied type description is invalid".into(),
@@ -233,11 +251,14 @@ impl DiagnosableError for CheckErrors {
233251
CheckErrors::UnionTypeError(expected_types, found_type) => format!("expecting expression of type {}, found '{}'", formatted_expected_types(expected_types), found_type),
234252
CheckErrors::UnionTypeValueError(expected_types, found_type) => format!("expecting expression of type {}, found '{}'", formatted_expected_types(expected_types), found_type),
235253
CheckErrors::ExpectedOptionalType(found_type) => format!("expecting expression of type 'optional', found '{}'", found_type),
254+
CheckErrors::ExpectedOptionalOrResponseType(found_type) => format!("expecting expression of type 'optional' or 'response', found '{}'", found_type),
255+
CheckErrors::ExpectedOptionalOrResponseValue(found_type) => format!("expecting expression of type 'optional' or 'response', found '{}'", found_type),
236256
CheckErrors::ExpectedResponseType(found_type) => format!("expecting expression of type 'response', found '{}'", found_type),
237257
CheckErrors::ExpectedOptionalValue(found_type) => format!("expecting expression of type 'optional', found '{}'", found_type),
238258
CheckErrors::ExpectedResponseValue(found_type) => format!("expecting expression of type 'response', found '{}'", found_type),
239259
CheckErrors::CouldNotDetermineResponseOkType => format!("attempted to obtain 'ok' value from response, but 'ok' type is indeterminate"),
240260
CheckErrors::CouldNotDetermineResponseErrType => format!("attempted to obtain 'err' value from response, but 'err' type is indeterminate"),
261+
CheckErrors::CouldNotDetermineMatchTypes => format!("attempted to match on an (optional) or (response) type where either the some, ok, or err type is indeterminate. you may wish to use unwrap-panic or unwrap-err-panic instead."),
241262
CheckErrors::BadTupleFieldName => format!("invalid tuple field name"),
242263
CheckErrors::ExpectedTuple(type_signature) => format!("expecting tuple, found '{}'", type_signature),
243264
CheckErrors::NoSuchTupleField(field_name, tuple_signature) => format!("cannot find field '{}' in tuple '{}'", field_name, tuple_signature),
@@ -275,6 +296,7 @@ impl DiagnosableError for CheckErrors {
275296
CheckErrors::RequiresAtLeastArguments(expected, found) => format!("expecting >= {} argument, got {}", expected, found),
276297
CheckErrors::IncorrectArgumentCount(expected_count, found_count) => format!("expecting {} arguments, got {}", expected_count, found_count),
277298
CheckErrors::IfArmsMustMatch(type_1, type_2) => format!("expression types returned by the arms of 'if' must match (got '{}' and '{}')", type_1, type_2),
299+
CheckErrors::MatchArmsMustMatch(type_1, type_2) => format!("expression types returned by the arms of 'match' must match (got '{}' and '{}')", type_1, type_2),
278300
CheckErrors::DefaultTypesMustMatch(type_1, type_2) => format!("expression types passed in 'default-to' must match (got '{}' and '{}')", type_1, type_2),
279301
CheckErrors::TooManyExpressions => format!("reached limit of expressions"),
280302
CheckErrors::IllegalOrUnknownFunctionApplication(function_name) => format!("use of illegal / unresolved function '{}", function_name),

Diff for: src/vm/analysis/read_only_checker/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ impl <'a, 'b> ReadOnlyChecker <'a, 'b> {
161161
Add | Subtract | Divide | Multiply | CmpGeq | CmpLeq | CmpLess | CmpGreater |
162162
Modulo | Power | BitwiseXOR | And | Or | Not | Hash160 | Sha256 | Keccak256 | Equals | If |
163163
Sha512 | Sha512Trunc256 |
164-
ConsSome | ConsOkay | ConsError | DefaultTo | Expects | ExpectsErr | IsOkay | IsNone | Asserts |
165-
ToUInt | ToInt | Append | Concat | AssertsMaxLen |
164+
ConsSome | ConsOkay | ConsError | DefaultTo | UnwrapRet | UnwrapErrRet | IsOkay | IsNone | Asserts |
165+
Unwrap | UnwrapErr | Match | IsErr | IsSome | TryRet |
166+
ToUInt | ToInt | Append | Concat | AsMaxLen |
166167
ListCons | GetBlockInfo | TupleGet | Len | Print | AsContract | Begin | FetchVar | GetTokenBalance | GetAssetOwner => {
167168
self.check_all_read_only(args)
168169
},

0 commit comments

Comments
 (0)