eos icon indicating copy to clipboard operation
eos copied to clipboard

unpack_action_data - error: !"unresolvable": env.free.

Open filipniziol opened this issue 8 years ago • 6 comments

I am trying to use unpack_action_data.

void apply(const account_name contract, const account_name act) {

		if (act == N(transfer)) {
			transferReceived(eosio::unpack_action_data<currency::transfer>(), contract);
			return;
		}
	}

Getting an error:

2725650ms thread-0 main.cpp:2493 main ] Failed with error: Assert Exception (10) !"unresolvable": env.free

What header file is missing? I do not see it anywhere

filipniziol avatar Jun 06 '18 09:06 filipniziol

Is it possible to get the complete contract?

heifner avatar Jun 06 '18 13:06 heifner

Sure - here is the code - this is test only, I would like just to make work this listening to the other contract (in this case irespo.token)

So here is the transfers.cpp file (just a sample test method apart from the one does not work):

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
#include <eosiolib/asset.hpp>
#include <eosiolib/symbol.hpp>
#include <eosiolib/system.h>
#include <eosiolib/currency.hpp>
#include <eosiolib/transaction.hpp>
#include <eosiolib/singleton.hpp>
#include <eosiolib/crypto.h>
#include <../eosio.token/eosio.token.hpp>

using namespace eosio;
using namespace std;

class transfers : public contract {
	using contract::contract;

public:
	transfers(account_name self) :
		contract(self){}

	// @abi-action
	void test(name sender, extended_asset payment, name receiver1, name receiver2, name receiver3) {	
		print("Hello");
	}
	void apply(const account_name contract, const account_name act) {

		if (act == N(transfer)) {
			transferReceived(eosio::unpack_action_data<currency::transfer>(), contract);
			return;
		}
	}

private:
	void transferReceived(const currency::transfer &transfer, const uint64_t code) {
		print("Hello");
	}
};

//EOSIO_ABI(transfers, (test))

extern "C" {

	/// The apply method implements the dispatch of events to this contract
	void apply(uint64_t receiver, uint64_t code, uint64_t action){
		if (receiver == N(transfers) && code == N(irespo.token) && action == N(transfer)) {
			transfers tr(receiver);
			tr.apply(code, action);
			eosio_exit(0);
		}
	}
}

And transfers.abi:

{
  "____comment": "This file was generated by eosio-abigen. DO NOT EDIT - 2018-06-06T08:39:00",
  "version": "",
  "types": [],
  "structs": [{
      "name": "test",
      "base": "",
      "fields": [{
          "name": "sender",
          "type": "name"
        },{
          "name": "payment",
          "type": "extended_asset"
        },{
          "name": "receiver1",
          "type": "name"
        },{
          "name": "receiver2",
          "type": "name"
        },{
          "name": "receiver3",
          "type": "name"
        }
      ]
    }
  ],
  "actions": [{
      "name": "test",
      "type": "test",
      "ricardian_contract": ""
    }
  ],
  "tables": [],
  "ricardian_clauses": [],
  "error_messages": [],
  "abi_extensions": []
}



filipniziol avatar Jun 06 '18 16:06 filipniziol

Same problem here (v1.0.6): https://eosio.stackexchange.com/questions/1129/can-not-unpack-data-from-received-eosio-tokentransfer-action

renatyv avatar Jun 24 '18 20:06 renatyv

Can you try with the latest version?

taokayan avatar Jun 25 '18 06:06 taokayan

commit 796511999b46063640396e9cd691a5262bab8207 (HEAD -> master, tag: v1.0.6, origin/master, origin/HEAD)

rm -rf build ./eosio_build.sh cd build sudo make install

eosiocpp -o accountsale.wast accountsale.cpp cleos set contract accountsale . accountsale.wast accountsale.abi 2709803ms thread-0 main.cpp:2712 main ] Failed with error: Assert Exception (10) !"unresolvable": env.free

accountsale.cpp

#include <eosiolib/eosio.hpp>
#include <eosiolib/asset.hpp>
#include <eosiolib/currency.hpp>
#include <math.h>

using eosio::name;
using eosio::print;
using eosio::currency;

namespace accountsale{
   struct impl
   {
      void apply(uint64_t receiver, uint64_t code, uint64_t action) {
         if (action == N(transfer)) {
            const eosio::currency::transfer& t = eosio::unpack_action_data<eosio::currency::transfer>();
         }else{
            eosio::print("action",name{action});
         }
      }
   };
}

using accountsale::impl;
extern "C" {
   void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
      accountsale::impl().apply(receiver,code,action);
   }
}

accountsale.abi

{
  "version": "eosio::abi/1.0",
  "types": [],
  "structs": [],
  "actions": [],
  "tables": [],
  "ricardian_clauses": [],
  "abi_extensions": []
}

renatyv avatar Jun 25 '18 11:06 renatyv

It works in the latest version

filipniziol avatar Aug 08 '18 16:08 filipniziol