Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a @apply decorator #62

Closed
jafri opened this issue Apr 24, 2022 · 3 comments
Closed

Add a @apply decorator #62

jafri opened this issue Apr 24, 2022 · 3 comments

Comments

@jafri
Copy link
Collaborator

jafri commented Apr 24, 2022

In some cases it would be very useful to provide a custom apply function that the contract uses instead of the generated one

For example a contract with just this:

export function apply(receiver: u64, firstReceiver: u64, action: u64): void {
	if (receiver != firstReceiver) {
		requireRecipient(Name.fromString("account"))
	}
	return;
}
@learnforpractice
Copy link
Contributor

commit aa450d7 should satisfy your need.

@jafri
Copy link
Collaborator Author

jafri commented Apr 25, 2022

Yup that works!

One interesting thing though is that WASM from ascdk here is 4KB while same code from blanc++ is 124 bytes. Roughly 30-40x larger.

ascdk code

import { Name, requireRecipient } from "as-chain"

@contract
class ForwardedContract {}

export function apply(receiver: u64, firstReceiver: u64, action: u64): void {
	if (receiver != firstReceiver) {
            requireRecipient(Name.fromString("sf"))
	}
	return;
}

blanc++

#include <eosio/eosio.hpp>

class [[eosio::contract]] forwarder : public eosio::contract {
public:
   using contract::contract;
};

extern "C" {
   [[eosio::wasm_entry]]
   void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
      if(code != receiver) {
         require_recipient("sf"_n);
      }
   }
}

@jafri
Copy link
Collaborator Author

jafri commented Apr 25, 2022

Ah I can achieve same result with this:

import * as env from 'as-chain/env'

@contract
class ForwardedContract {}

export function apply(receiver: u64, firstReceiver: u64, action: u64): void {
	if (receiver != firstReceiver) {
        env.require_recipient(14033216438886465536); // proton encode:name sf
	}
}

@jafri jafri closed this as completed Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants