Code Monkey home page Code Monkey logo

Comments (6)

deckb avatar deckb commented on July 30, 2024

You should be using the Cleos.abi_json_to_bin to convert the payload. The ABI is not fully functional yet.

data = ce.abi_json_to_bin(payload['account'], payload['name'], arguments)

from eospy.

luxasjer avatar luxasjer commented on July 30, 2024

Thanks for replying. data = ce.abi_json_to_bin(payload['account'], payload['name'], arguments) is ok.

Here is my code. When running, Line 57 error.

import eospy.cleos
import eospy.keys
from eospy.types import Abi, Action
from eospy.utils import parse_key_file
import os
import pytz
import json


ce = eospy.cleos.Cleos(url='https://eos.greymass.com:443')

# use a string or EOSKey for push_transaction
# # use EOSKey:
key = eospy.keys.EOSKey('5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3')


script_dir = os.path.dirname(os.path.realpath(__file__))


########################################
# VOTE
########################################

abi_file = os.path.join(script_dir, 'eosio.system.abi')

with open(abi_file) as rf:
    abi_json = json.load(rf)
    sys_abi = Abi(abi_json)

    # wait to send transaction
    import time
    print('Pushing a vote after 2 seconds using abi file: {}'.format(abi_file))
    time.sleep(2)

    vote_payload = {
        "account": "eosio",
        "name": "voteproducer",
        "authorization": [{
            "actor": "eosaccount",
            "permission": "active",
        }],
    }

    vote_params = {
        "voter": "eosaccount",  # sender
        "proxy": "eosproxy",  # proxy
        "producers": []  # producers
    }

    # Voting Converting payload to binary
    data = ce.abi_json_to_bin(vote_payload['account'], vote_payload['name'], vote_params)
    print(data)


############################### Problem ######################################

    vote_data = sys_abi.json_to_bin(vote_payload['name'], vote_params)

############################### Problem   ######################################

    # Inserting payload binary form as "data" field in original payload
    vote_payload['data'] = vote_data
    print(vote_payload)
    # final transaction formed
    trx = {"actions": [vote_payload]}

    # resp = ce.push_transaction(trx, eospy.keys.EOSKey(key), broadcast=True)
    print('------------------------------------------------')
    print(resp)
    print('------------------------------------------------')

runing result:

Traceback (most recent call last):
  File "p.py", line 57, in <module>
    vote_data = sys_abi.json_to_bin(vote_payload['name'], vote_params)
AttributeError: 'Abi' object has no attribute 'json_to_bin'

from eospy.

deckb avatar deckb commented on July 30, 2024

What version of eospy are you running?

from eospy.

luxasjer avatar luxasjer commented on July 30, 2024

just git clone url, not use release edition.

from eospy.

deckb avatar deckb commented on July 30, 2024

I just ran the following using python 3.7 with master and it worked for me.

from eospy.types import Abi, Action
import json

abi_file = "/home/deck/Documents/git/eosnewyork/eospy/examples/eosio.system.abi"

with open(abi_file) as rf:
    abi_json = json.load(rf)
    sys_abi = Abi(abi_json)

    vote_payload = {
        "account": "eosio",
        "name": "voteproducer",
        "authorization": [{
            "actor": "eosaccount",
            "permission": "active",
        }],
    }

    vote_params = {
        "voter": "eosaccount",  # sender
        "proxy": "eosproxy",  # proxy
        "producers": []  # producers
    }

    data = sys_abi.json_to_bin(vote_payload['name'], vote_params)
    print(data)

from eospy.

luxasjer avatar luxasjer commented on July 30, 2024

maybe the different versions of the dependencies. I run in another mbp, it worked. Thanks for replying. (PS. this issue can close)

from eospy.

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.