跳到主要内容

libraries/eosiolib/contracts/eosio/permission.hpp

More...

Namespaces

Name
eosio
eosio::internal_use_do_not_use

Detailed Description

Copyright: defined in eos/LICENSE

Source code


#pragma once

#include "transaction.hpp"
#include "../../core/eosio/crypto.hpp"
#include "../../core/eosio/name.hpp"
#include "../../core/eosio/time.hpp"

#include <set>
#include <limits>

namespace eosio {
namespace internal_use_do_not_use {
extern "C" {
__attribute__((eosio_wasm_import))
int32_t check_transaction_authorization(const char*, uint32_t,
const char*, uint32_t,
const char*, uint32_t);
__attribute__((eosio_wasm_import))
int32_t check_permission_authorization( uint64_t, uint64_t,
const char*, uint32_t,
const char*, uint32_t,
uint64_t);
__attribute__((eosio_wasm_import))
int64_t get_permission_last_used(uint64_t, uint64_t);

__attribute__((eosio_wasm_import))
int64_t get_account_creation_time(uint64_t);
}
}

bool
check_transaction_authorization( const char* trx_data, uint32_t trx_size,
const char* pubkeys_data, uint32_t pubkeys_size,
const char* perms_data, uint32_t perms_size ) {
return internal_use_do_not_use::check_transaction_authorization( trx_data, trx_size, pubkeys_data, pubkeys_size, perms_data, perms_size );
}

bool
check_permission_authorization( name account,
name permission,
const char* pubkeys_data, uint32_t pubkeys_size,
const char* perms_data, uint32_t perms_size,
microseconds delay ) {
int64_t delay_us = delay.count();
check(delay_us >= 0, "negative delay is not allowed");
return internal_use_do_not_use::check_permission_authorization( account.value, permission.value, pubkeys_data, pubkeys_size, perms_data, perms_size, static_cast<uint64_t>(delay_us) );
}


bool
check_transaction_authorization( const transaction& trx,
const std::set<permission_level>& provided_permissions ,
const std::set<public_key>& provided_keys = std::set<public_key>()
)
{
auto packed_trx = pack(trx);

std::vector<char> packed_keys;
auto nkeys = provided_keys.size();
if( nkeys > 0 ) {
packed_keys = pack(provided_keys);
}

std::vector<char> packed_perms;
auto nperms = provided_permissions.size();
if( nperms > 0 ) {
packed_perms = pack(provided_permissions);
}

auto res = internal_use_do_not_use::check_transaction_authorization( packed_trx.data(),
packed_trx.size(),
(nkeys > 0) ? packed_keys.data() : (const char*)0,
(nkeys > 0) ? packed_keys.size() : 0,
(nperms > 0) ? packed_perms.data() : (const char*)0,
(nperms > 0) ? packed_perms.size() : 0
);

return (res > 0);
}

bool
check_permission_authorization( name account,
name permission,
const std::set<public_key>& provided_keys,
const std::set<permission_level>& provided_permissions = std::set<permission_level>(),
microseconds provided_delay = microseconds{std::numeric_limits<int64_t>::max()}
)
{
int64_t provided_delay_us = provided_delay.count();
check(provided_delay_us >= 0, "negative delay is not allowed");
std::vector<char> packed_keys;
auto nkeys = provided_keys.size();
if( nkeys > 0 ) {
packed_keys = pack(provided_keys);
}

std::vector<char> packed_perms;
auto nperms = provided_permissions.size();
if( nperms > 0 ) {
packed_perms = pack(provided_permissions);
}

auto res = internal_use_do_not_use::check_permission_authorization( account.value,
permission.value,
(nkeys > 0) ? packed_keys.data() : (const char*)0,
(nkeys > 0) ? packed_keys.size() : 0,
(nperms > 0) ? packed_perms.data() : (const char*)0,
(nperms > 0) ? packed_perms.size() : 0,
static_cast<uint64_t>(provided_delay_us)
);

return (res > 0);
}

time_point get_permission_last_used( name account, name permission ) {
return time_point(
microseconds(
internal_use_do_not_use::get_permission_last_used(account.value, permission.value)));

}

time_point get_account_creation_time( name account ) {
return time_point(
microseconds(
internal_use_do_not_use::get_account_creation_time(account.value)));

}
}

Updated on 2022-12-05 at 15:38:08 +0000