Selaa lähdekoodia

Timestamp should be seconds

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 5 vuotta sitten
vanhempi
sitoutus
200a9b49cd
4 muutettua tiedostoa jossa 14 lisäystä ja 4 poistoa
  1. 1 1
      Cargo.toml
  2. 1 1
      docs/conf.py
  3. 11 1
      src/emit/substrate.rs
  4. 1 1
      tests/substrate.rs

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "solang"
-version = "0.1.1"
+version = "0.1.2"
 authors = ["Sean Young <sean@mess.org>"]
 homepage = "https://github.com/hyperledger-labs/solang"
 documentation = "https://solang.readthedocs.io/"

+ 1 - 1
docs/conf.py

@@ -22,7 +22,7 @@ copyright = '2019, Sean Young <sean@mess.org>'
 author = 'Sean Young <sean@mess.org>'
 
 # The full version, including alpha/beta/rc tags
-release = '0.1.1'
+release = '0.1.2'
 
 
 # -- General configuration ---------------------------------------------------

+ 11 - 1
src/emit/substrate.rs

@@ -3015,7 +3015,17 @@ impl TargetRuntime for SubstrateTarget {
                 get_seal_value!("block_number", "ext_block_number", 64)
             }
             ast::Expression::Builtin(_, _, ast::Builtin::Timestamp, _) => {
-                get_seal_value!("timestamp", "ext_now", 64)
+                let milliseconds = get_seal_value!("timestamp", "ext_now", 64).into_int_value();
+
+                // Solidity expects the timestamp in seconds, not milliseconds
+                contract
+                    .builder
+                    .build_int_unsigned_div(
+                        milliseconds,
+                        contract.context.i64_type().const_int(1000, false),
+                        "seconds",
+                    )
+                    .into()
             }
             ast::Expression::Builtin(_, _, ast::Builtin::Gasleft, _) => {
                 get_seal_value!("gas_left", "ext_gas_left", 64)

+ 1 - 1
tests/substrate.rs

@@ -626,7 +626,7 @@ impl Externals for TestRuntime {
                 Ok(None)
             }
             Some(SubstrateExternal::ext_now) => {
-                self.vm.scratch = 1594035638u64.to_le_bytes().to_vec();
+                self.vm.scratch = 1594035638000u64.to_le_bytes().to_vec();
 
                 println!("ext_now: {}", hex::encode(&self.vm.scratch));