Simple Contract Source
Coding the Simple Contract's source file
Defining the Contract Constructors and Dump Function
#include "simplecontract.h"
#include "../../utils/uintconv.h"
#include "../../utils/utils.h"
SimpleContract::SimpleContract(
const std::string& name,
const uint256_t& number,
const std::tuple<std::string, uint256_t>& tuple,
const Address& address,
const Address& creator,
const uint64_t& chainId
) : DynamicContract("SimpleContract", address, creator, chainId),
name_(this), number_(this), tuple_(this)
{
this->name_ = name;
this->number_ = number;
this->tuple_ = tuple;
this->name_.commit();
this->number_.commit();
this->tuple_.commit();
registerContractFunctions();
this->name_.enableRegister();
this->number_.enableRegister();
this->tuple_.enableRegister();
}
SimpleContract::SimpleContract(
const Address& address,
const DB& db
) : DynamicContract(address, db), name_(this), number_(this), tuple_(this) {
this->name_ = StrConv::bytesToString(db.get(std::string("name_"), this->getDBPrefix()));
this->number_ = UintConv::bytesToUint256(db.get(std::string("number_"), this->getDBPrefix()));
this->tuple_ = std::make_tuple(
StrConv::bytesToString(db.get(std::string("tuple_name"), this->getDBPrefix())),
UintConv::bytesToUint256(db.get(std::string("tuple_number"), this->getDBPrefix()))
);
this->name_.commit();
this->number_.commit();
this->tuple_.commit();
registerContractFunctions();
this->name_.enableRegister();
this->number_.enableRegister();
this->tuple_.enableRegister();
}
DBBatch SimpleContract::dump() const {
DBBatch dbBatch;
dbBatch.push_back(StrConv::stringToBytes("name_"), StrConv::stringToBytes(this->name_.get()), this->getDBPrefix());
dbBatch.push_back(StrConv::stringToBytes("number_"), UintConv::uint256ToBytes(this->number_.get()), this->getDBPrefix());
dbBatch.push_back(StrConv::stringToBytes("tuple_name"), StrConv::stringToBytes(get<0>(this->tuple_)), this->getDBPrefix());
dbBatch.push_back(StrConv::stringToBytes("tuple_number"), UintConv::uint256ToBytes(get<1>(this->tuple_)), this->getDBPrefix());
return dbBatch;
}Defining the Contract Functions
Registering the Contract Functions
Last updated