smartpy_io | Unsorted

Telegram-канал smartpy_io - SmartPy

429

https://smartpy.io/ https://twitter.com/smartpy_io

Subscribe to a channel

SmartPy

but this solution is far better

Читать полностью…

SmartPy

If your goal is to compile from Python code instead of invoking python3 contract.py, you can do it through a test scenario: instantiate the contract, add it to the scenario, and then read the compiled code and initial storage from origination_result. Like that:

import smartpy as sp

@sp.module
def main():
class C(sp.Contract):
def __init__(self, x: sp.int):
self.data.x = x

@sp.entrypoint
def ep(self):
pass

def compile_contract(contract_ref, *args):
scenario = sp.test_scenario()
contract = contract_ref(*args)
scenario += contract
return {
"code_json": contract.origination_result["code_json"],
"storage_json": contract.origination_result["storage_json"],
"code_tz": contract.origination_result["code_tz"],
"storage_tz": contract.origination_result["storage_tz"],
}

result = compile_contract(main.C, 0)


But there is no official SmartPy api that provides a function equivalent to compile_contract, you have to build it yourself.

Читать полностью…

SmartPy

So the michelson runtime/tezos runtime will return a list of operations to the chain to be run after the entrypoint logic is done, so this will mitigate against common reentrancy attacks, however there are still things to be aware of, e.g. see:
https://octez.tezos.com/docs/alpha/michelson_anti_patterns.html

smartpy tracks the effects of functions and entrypoints that perform operations - and should not let you run effectful stuff from non-effectful code - this should in fact be a compilation error.

See with_operations: https://smartpy.tezos.com/manual/data-types/effects.html#effects

Читать полностью…

SmartPy

And is possible to read an address balance?

Читать полностью…

SmartPy

Is the inability to read the balance of another smart contract a limitation of SmartPy, or is Michelson designed that way?

Читать полностью…

SmartPy

Yes, that's the only way currently.
Which alternative are you thinking of? It's not exactly that is truly necessary, simply that currently it's the way.

Читать полностью…

SmartPy

No...
That's a good request. Maybe a design could be x = my_list.pip(error=...) or x=my_list.pop(default=...).
I'm a bit responsible for the fact there is no such thing.

What you can do it matching over head and tail the way I showed in my zip example.

Читать полностью…

SmartPy

It's okay, no need to mention me.

Читать полностью…

SmartPy

It's more a design choice because of how Tezos internal way of representing list is a chained list so accessing the index n costs o(n). A request could be to allow it in constructor as constructor cost isn't a problem.

Читать полностью…

SmartPy

have you github:tag? I want to mention you in commit for this version, even if I had to change it in the future

Читать полностью…

SmartPy

yes I noticed that problem about nat and negative form subs

Читать полностью…

SmartPy

I think it's a wrong idea to do it in a 1:1 at least in this case. The version I'm proposing is far easier to read and corresponds to the requirements.
My version is close to yours (AI is probably the reason). Mine fixes a bug: there will be an error if the tez subtraction is lower than zero so your error will never be raised. As the requirements aren't saying we should fail I just used a if. You can also keep your version but invert the assert and the subtraction.

Читать полностью…

SmartPy

I'll make some edit because I need to have same name for var and fun, also for the views

Читать полностью…

SmartPy

here the updated version I'm working on lately

Читать полностью…

SmartPy

Oh yes, it was different from the solidity one

Читать полностью…

SmartPy

Oh thanks, because i'm working on a toolchain for automatic execution and testing and through python code I was calling the bash for compiling code

Читать полностью…

SmartPy

It's possible to compile a smartpy contract via library function instead of calling it with 'python3 contract.py' ?

Читать полностью…

SmartPy

And is smartpy/michelson safe to reentrancy pattern?

Читать полностью…

SmartPy

It's a Michelson limitation

Читать полностью…

SmartPy

Just for the record, actually, because I was keeping the raw code and the scenario separate to keep the contracts cleaner, but then I realized it wasn’t compiling—or rather, it wasn’t generating the output files correctly for deployment. So what’s the bare minimum required to get them?

@sp.add_test()
def test():
sc = sp.test_scenario("SmartContract")
c1 = main.SmartContract()
sc += c1

Читать полностью…

SmartPy

The only way to compile a contract locally is to use the scenario? If so, why is it necessary?

Читать полностью…

SmartPy

there's a way to pop the first element of a list? or the last

Читать полностью…

SmartPy

Now this could also be debatable in the context of the Tezlink layer 2

Читать полностью…

SmartPy

If you will be able in the next smartpy versions to add index access to sp.list as normal python it would be really usefull😄

Читать полностью…

SmartPy

In fact you can remove it when you know what you're doing, nobody should do that basically for now.

Читать полностью…

SmartPy

It's a good idea to put it back, sorry.

Читать полностью…

SmartPy

I'll ask to coordinator for parameter, if it's mandatory to have payee and shares splitted or map is good too

Читать полностью…

SmartPy

a question, why did you not use @sp.add_test?

Читать полностью…

SmartPy

Now i'm trying to make a 1:1 replica

Читать полностью…

SmartPy

Yes, the payment splitter.
Here is my version. Please check the validity before pushing it. Also, I would use black over it and column split for comments.

Читать полностью…
Subscribe to a channel