Skip to content

Commit

Permalink
Transferdomain changes to master (#2035)
Browse files Browse the repository at this point in the history
* Transferdomain and dependencies.

* Fix rpc command

* Minor refinements

* Use reference wrapper

* Cleanup EthAuth

* Cleanup auth, add auth strategy

* Hoist IsSpent check out

* Fix univalue stack location

* Move error strings into DeFiErrors

* Rename CTransferDomain and change add/sub calls

---------

Co-authored-by: Prasanna Loganathar <[email protected]>
Co-authored-by: Shoham Chakraborty <[email protected]>
Co-authored-by: Peter Bushnell <[email protected]>
  • Loading branch information
4 people authored Jun 9, 2023
1 parent 02a5983 commit 262202e
Show file tree
Hide file tree
Showing 16 changed files with 437 additions and 215 deletions.
11 changes: 6 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.code
.cache
.idea

# Editors.
Expand All @@ -12,11 +13,12 @@

# Build
build/
build.*/
out/
*.exe
*.pdb

# Univalue
# Univalue

src/defi
src/defid
Expand Down Expand Up @@ -141,7 +143,6 @@ contrib/devtools/split-debug.sh
# CI scratch area used for tests
/ci/scratch/

# Potential rust paths to keep things clean
# as we switch between branches
/src/rust/target
/lib/target
# Rust local artifacts
/lib/target
*.bin
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.code
.cache
.idea

# Editors.
Expand All @@ -12,11 +13,12 @@

# Build
build/
build.*/
out/
*.exe
*.pdb

# Univalue
# Univalue

src/defi
src/defid
Expand Down Expand Up @@ -141,7 +143,6 @@ contrib/devtools/split-debug.sh
# CI scratch area used for tests
/ci/scratch/

# Potential rust paths to keep things clean
# as we switch between branches
/src/rust/target
/lib/target
# Rust local artifacts
/lib/target
*.bin
2 changes: 1 addition & 1 deletion src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct DCT_ID {
static constexpr CAmount COIN = 100000000;
static constexpr CAmount CENT = 1000000;
static constexpr int64_t WEI_IN_GWEI = 1000000000;
static constexpr int64_t CAMOUNT_TO_WEI = 10;
static constexpr int64_t CAMOUNT_TO_GWEI = 10;

//Converts the given value to decimal format string with COIN precision.
inline std::string GetDecimalString(CAmount nValue)
Expand Down
42 changes: 31 additions & 11 deletions src/masternodes/balances.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,44 @@ struct CUtxosToAccountMessage {
}
};

enum CTransferBalanceType : uint8_t {
AccountToAccount = 0x00,
EvmIn = 0x01,
EvmOut = 0x02,
enum VMDomain : uint8_t {
NONE = 0x00,
// UTXO Reserved
UTXO = 0x01,
DVM = 0x02,
EVM = 0x03,
};

struct CTransferBalanceMessage {
uint8_t type;
CAccounts from; // from -> balances
CAccounts to; // to -> balances
struct CTransferDomainItem
{
CScript address;
CTokenAmount amount;
uint8_t domain;

// Optional data that'll vary based on the domain.
// EVMData, UTXOData with inputs, etc.
// Currently, unused.
std::vector<uint8_t> data;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream &s, Operation ser_action) {
READWRITE(type);
READWRITE(from);
READWRITE(to);
READWRITE(address);
READWRITE(amount);
READWRITE(domain);
READWRITE(data);
}
};

struct CTransferDomainMessage {
std::vector<std::pair<CTransferDomainItem, CTransferDomainItem>> transfers;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream &s, Operation ser_action) {
READWRITE(transfers);
}
};

Expand Down
48 changes: 48 additions & 0 deletions src/masternodes/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,54 @@ class DeFiErrors {
static Res AccountsFuturesErase() {
return Res::Err("Failed to erase futures");
}

static Res TransferDomainNotEnoughBalance(const std::string address) {
return Res::Err("Not enough balance in %s to cover \"EVM\" domain transfer", address);
}

static Res InvalidAuth() {
return Res::Err("tx must have at least one input from account owner");
}

static Res TransferDomainEVMNotEnabled() {
return Res::Err("Cannot create tx, EVM is not enabled");
}

static Res TransferDomainSameDomain() {
return Res::Err("Cannot transfer inside same domain");
}

static Res TransferDomainUnequalAmount() {
return Res::Err("Source amount must be equal to destination amount");
}

static Res TransferDomainIncorrectToken() {
return Res::Err("For transferdomain, only DFI token is currently supported");
}

static Res TransferDomainETHSourceAddress() {
return Res::Err("Src address must not be an ETH address in case of \"DVM\" domain");
}

static Res TransferDomainDFISourceAddress() {
return Res::Err("Src address must be an ETH address in case of \"EVM\" domain");
}

static Res TransferDomainInvalidSourceDomain() {
return Res::Err("Invalid domain set for \"src\" argument");
}

static Res TransferDomainETHDestinationAddress() {
return Res::Err("Dst address must not be an ETH address in case of \"DVM\" domain");
}

static Res TransferDomainDVMDestinationAddress() {
return Res::Err("Dst address must be an ETH address in case of \"EVM\" domain");
}

static Res TransferDomainInvalidDestinationDomain() {
return Res::Err("Invalid domain set for \"dst\" argument");
}
};

#endif // DEFI_MASTERNODES_ERRORS_H
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/evm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ constexpr const uint16_t EVM_TX_SIZE = 32768;

using CRawEvmTx = TBytes;

extern std::string CTransferBalanceTypeToString(const CTransferBalanceType type);
extern std::string CTransferDomainToString(const VMDomain domain);

struct CEvmTxMessage {
CRawEvmTx evmTx;
Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/ffi_temp_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ inline uint64_t evm_get_balance(::rust::Str address) {
return {};
}

inline void evm_add_balance(::std::uint64_t context, ::rust::Str address, ::std::array<::std::uint8_t, 32> amount) {}
inline void evm_add_balance(::std::uint64_t context, ::rust::Str address, ::std::array<::std::uint8_t, 32> amount, ::std::array<::std::uint8_t, 32> native_tx_hash) {}

inline bool evm_sub_balance(::std::uint64_t context, ::rust::Str address, ::std::array<::std::uint8_t, 32> amount) {
inline bool evm_sub_balance(::std::uint64_t context, ::rust::Str address, ::std::array<::std::uint8_t, 32> amount, ::std::array<::std::uint8_t, 32> native_tx_hash) {
return {};
}

Expand Down
Loading

0 comments on commit 262202e

Please sign in to comment.