1
- use std:: borrow:: BorrowMut ;
2
- use std:: collections:: { BTreeMap , HashMap } ;
3
- use std:: f32:: EPSILON ;
4
- use std:: fs:: File ;
5
- use std:: io:: Write ;
6
-
7
1
use stacks_common:: types:: chainstate:: StacksBlockId ;
8
2
use stacks_common:: types:: StacksEpochId ;
9
3
use stacks_common:: util:: hash:: { Keccak256Hash , Sha512Sum , Sha512Trunc256Sum } ;
10
4
use stacks_common:: util:: secp256k1:: { secp256k1_recover, secp256k1_verify, Secp256k1PublicKey } ;
11
- use wasmtime:: { AsContextMut , Caller , Engine , Linker , Memory , Module , Store , Trap , Val , ValType } ;
5
+ use wasmtime:: { AsContextMut , Caller , Linker , Memory , Module , Store , Val , ValType } ;
12
6
13
- use super :: analysis:: { CheckError , CheckErrors } ;
7
+ use super :: analysis:: CheckErrors ;
14
8
use super :: ast:: { build_ast_with_rules, ASTRules } ;
15
9
use super :: callables:: { DefineType , DefinedFunction } ;
16
- use super :: contracts:: Contract ;
17
- use super :: costs:: { constants as cost_constants, CostTracker , LimitedCostTracker } ;
18
- use super :: database:: clarity_db:: ValueResult ;
19
- use super :: database:: { ClarityDatabase , DataVariableMetadata , STXBalance } ;
10
+ use super :: costs:: { constants as cost_constants, CostTracker } ;
11
+ use super :: database:: STXBalance ;
20
12
use super :: errors:: RuntimeErrorType ;
21
13
use super :: events:: * ;
22
14
use super :: functions:: crypto:: { pubkey_to_address_v1, pubkey_to_address_v2} ;
23
15
use super :: types:: signatures:: CallableSubtype ;
24
16
use super :: types:: {
25
- ASCIIData , AssetIdentifier , BlockInfoProperty , BuffData , BurnBlockInfoProperty , CallableData ,
26
- CharType , FixedFunction , FunctionType , ListData , ListTypeData , OptionalData , PrincipalData ,
27
- QualifiedContractIdentifier , ResponseData , SequenceData , StacksAddressExtensions ,
28
- StandardPrincipalData , TraitIdentifier , TupleData , TupleTypeSignature , UTF8Data , BUFF_1 ,
29
- BUFF_32 , BUFF_33 ,
17
+ ASCIIData , AssetIdentifier , BuffData , CallableData , CharType , FunctionType , ListData ,
18
+ ListTypeData , OptionalData , PrincipalData , QualifiedContractIdentifier , ResponseData ,
19
+ SequenceData , StacksAddressExtensions , StandardPrincipalData , TraitIdentifier , TupleData ,
20
+ TupleTypeSignature , BUFF_1 , BUFF_32 , BUFF_33 ,
30
21
} ;
31
22
use super :: { CallStack , ClarityVersion , ContractName , Environment , SymbolicExpression } ;
32
23
use crate :: vm:: analysis:: ContractAnalysis ;
33
- use crate :: vm:: ast:: ContractAST ;
34
24
use crate :: vm:: contexts:: GlobalContext ;
35
25
use crate :: vm:: errors:: { Error , WasmError } ;
36
- use crate :: vm:: functions:: principals;
37
26
use crate :: vm:: types:: {
38
27
BufferLength , SequenceSubtype , SequencedValue , StringSubtype , TypeSignature ,
39
28
} ;
@@ -890,7 +879,7 @@ fn read_from_wasm(
890
879
. read ( store. as_context_mut ( ) , current_offset, & mut hash)
891
880
. map_err ( |e| Error :: Wasm ( WasmError :: Runtime ( e. into ( ) ) ) ) ?;
892
881
current_offset += PRINCIPAL_HASH_BYTES ;
893
- let principal = StandardPrincipalData ( version[ 0 ] , hash) ;
882
+ let principal = StandardPrincipalData :: new ( version[ 0 ] , hash) ? ;
894
883
let mut contract_length_buf: [ u8 ; CONTRACT_NAME_LENGTH_BYTES ] =
895
884
[ 0 ; CONTRACT_NAME_LENGTH_BYTES ] ;
896
885
memory
@@ -1393,7 +1382,7 @@ fn write_to_wasm(
1393
1382
. write (
1394
1383
& mut store,
1395
1384
( in_mem_offset + in_mem_written) as usize ,
1396
- & [ standard. 0 ] ,
1385
+ & [ standard. version ( ) ] ,
1397
1386
)
1398
1387
. map_err ( |e| Error :: Wasm ( WasmError :: UnableToWriteMemory ( e. into ( ) ) ) ) ?;
1399
1388
in_mem_written += 1 ;
@@ -1645,9 +1634,11 @@ fn pass_argument_to_wasm(
1645
1634
buffer. push ( Val :: I32 ( written) ) ;
1646
1635
Ok ( ( buffer, offset + written, in_mem_offset + in_mem_written) )
1647
1636
}
1648
- Value :: Principal ( PrincipalData :: Standard ( StandardPrincipalData ( v , h ) ) ) => {
1637
+ Value :: Principal ( PrincipalData :: Standard ( data ) ) => {
1649
1638
let mut bytes: Vec < u8 > = Vec :: with_capacity ( 22 ) ;
1650
- bytes. push ( * v) ;
1639
+ let v = data. version ( ) ;
1640
+ let h = & data. 1 ;
1641
+ bytes. push ( v) ;
1651
1642
bytes. extend ( h) ;
1652
1643
bytes. push ( 0 ) ;
1653
1644
let buffer = vec ! [ Val :: I32 ( in_mem_offset) , Val :: I32 ( bytes. len( ) as i32 ) ] ;
@@ -1665,15 +1656,17 @@ fn pass_argument_to_wasm(
1665
1656
// Callable types can just ignore the optional trait identifier, and
1666
1657
// is handled like a qualified contract
1667
1658
let QualifiedContractIdentifier {
1668
- issuer : StandardPrincipalData ( v , h ) ,
1659
+ issuer,
1669
1660
name,
1670
1661
} = p;
1662
+ let v = issuer. version ( ) ;
1663
+ let h = & issuer. 1 ;
1671
1664
let bytes: Vec < u8 > = std:: iter:: once ( v)
1672
- . chain ( h. iter ( ) )
1673
- . chain ( std:: iter:: once ( & name. len ( ) ) )
1674
- . chain ( name. as_bytes ( ) )
1675
- . copied ( )
1665
+ . chain ( h. iter ( ) . copied ( ) )
1666
+ . chain ( std:: iter:: once ( name. len ( ) as u8 ) )
1667
+ . chain ( name. as_bytes ( ) . iter ( ) . copied ( ) )
1676
1668
. collect ( ) ;
1669
+
1677
1670
let buffer = vec ! [ Val :: I32 ( in_mem_offset) , Val :: I32 ( bytes. len( ) as i32 ) ] ;
1678
1671
memory
1679
1672
. write ( & mut store, in_mem_offset as usize , & bytes)
@@ -1970,14 +1963,14 @@ fn wasm_to_clarity_value(
1970
1963
memory
1971
1964
. read ( store. as_context_mut ( ) , offset as usize + 21 , & mut buffer)
1972
1965
. map_err ( |e| Error :: Wasm ( WasmError :: UnableToReadMemory ( e. into ( ) ) ) ) ?;
1973
- let standard = StandardPrincipalData (
1966
+ let standard = StandardPrincipalData :: new (
1974
1967
principal_bytes[ 0 ] ,
1975
1968
principal_bytes[ 1 ..] . try_into ( ) . map_err ( |_| {
1976
1969
Error :: Wasm ( WasmError :: WasmGeneratorError (
1977
1970
"Could not decode principal" . into ( ) ,
1978
1971
) )
1979
1972
} ) ?,
1980
- ) ;
1973
+ ) ? ;
1981
1974
let contract_name_length = buffer[ 0 ] as usize ;
1982
1975
if contract_name_length == 0 {
1983
1976
Ok ( ( Some ( Value :: Principal ( PrincipalData :: Standard ( standard) ) ) , 2 ) )
0 commit comments