Giter VIP home page Giter VIP logo

Comments (12)

ixje avatar ixje commented on August 29, 2024 1

It's been a while so I'm going to let it sink in and try to remember why I took this approach. If I can't come up with a good reason then we can change it to use PACK (should also be cheaper)

from neo-mamba.

ixje avatar ixje commented on August 29, 2024

I'm not sure I understand what you're referring to. Can you elaborate or point to the code where this is happening?

from neo-mamba.

ixje avatar ixje commented on August 29, 2024

You mean this?

neo-mamba/neo3/vm.py

Lines 333 to 339 in d7e2c02

elif isinstance(value, Sequence):
self.emit(OpCode.NEWARRAY0)
for v in value:
self.emit(OpCode.DUP)
self.emit_push(v)
self.emit(OpCode.APPEND)
return self

I'm open to suggestions on how you think we can improve it

from neo-mamba.

NeoDashboard avatar NeoDashboard commented on August 29, 2024

aaa
Sorry I'll try with a screenshot :) As you can see using last version of neo-mamba when passing a list as parameter It's using some opcodes I put in first message in the transaction script. But if I build It myself without those append/dup... It's still working so I'm wondering if there is something I'm missing?

from neo-mamba.

ixje avatar ixje commented on August 29, 2024

Can you share an example how you're building your array?

from neo-mamba.

NeoDashboard avatar NeoDashboard commented on August 29, 2024

I was using this on my side previously

class ScriptBuilderWithListSupport(vm.ScriptBuilder):
    def emit_push_list(self, items: list):
        for item in reversed(items):
            if type(item) is list:
                self.emit_push_list(item)
                continue
            self.emit_push(item)
        self.emit_push(len(items))
        self.emit(vm.OpCode.PACK)

    def emit_dynamic_call_with_args(self, script_hash, operation: str, args) -> None:
        self.emit_push_list(args)
        self.emit_push(0xF)
        self.emit_push(operation)
        self.emit_push(script_hash.to_array())
        self.emit_syscall(vm._syscall_name_to_int("System.Contract.Call"))

from neo-mamba.

NeoDashboard avatar NeoDashboard commented on August 29, 2024

This?

    def emit_push_list(self, items: list):
        for item in reversed(items):
            if type(item) is list:
                self.emit_push_list(item)
                continue
            self.emit_push(item)
        self.emit_push(len(items))
        self.emit(vm.OpCode.PACK)

from neo-mamba.

NeoDashboard avatar NeoDashboard commented on August 29, 2024

Yeap cheaper and more beautiful that's why I opened an issue :D

from neo-mamba.

ixje avatar ixje commented on August 29, 2024

It's been a while so I'm going to let it sink in and try to remember why I took this approach. If I can't come up with a good reason then we can change it to use PACK (should also be cheaper)

I can't think of anything at the moment, so open to accept a PR if you'd like

from neo-mamba.

NeoDashboard avatar NeoDashboard commented on August 29, 2024

Something like this? #255

from neo-mamba.

Devel484 avatar Devel484 commented on August 29, 2024

It's been a while so I'm going to let it sink in and try to remember why I took this approach. If I can't come up with a good reason then we can change it to use PACK (should also be cheaper)

I can't think of anything at the moment, so open to accept a PR if you'd like

The previous implementation with DUP and APPEND was used to invert the order of the emitted items . The solution from @NeoDashboard emits the items directly in the correct (inversed) order and is cheaper.

from neo-mamba.

ixje avatar ixje commented on August 29, 2024

Fixed in #256

from neo-mamba.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.