Skip to content

Commit

Permalink
[resolves trustwallet#260] fix test, clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Defuera committed May 30, 2019
1 parent df9b857 commit 40b637a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 41 deletions.
2 changes: 0 additions & 2 deletions include/TrustWalletCore/TWAeternitySigner.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// file LICENSE at the root of the source code distribution tree.
#pragma once

#include "TWBase.h"
#include "TWData.h"
#include "TWAeternityProto.h"

TW_EXTERN_C_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion src/Aeternity/Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ inline bool operator==(const Address& lhs, const Address& rhs) {
} // namespace TW::Aeternity


/// Wrapper for C interface.
// Wrapper for C interface.
struct TWAeternityAddress {
TW::Aeternity::Address impl;
};
20 changes: 11 additions & 9 deletions src/Aeternity/Transaction.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <utility>

// Copyright © 2017-2019 Trust.
//
// This file is part of Trust. The full Trust copyright notice, including
Expand All @@ -16,35 +18,35 @@ class Transaction {

public:
/// sender address
std::string &sender_id;
std::string sender_id;
/// recepient address
std::string &recipient_id;
std::string recipient_id;

uint64_t amount;

uint64_t fee;

/// message
std::string &payload;
std::string payload;

/// the block time that tx live on the mempool, you can use 0 by default, or >latest block
uint64_t ttl;
uint64_t nonce;

Transaction(
std::string &sender_id,
std::string &recipientId,
std::string sender_id, //todo
std::string recipientId,
uint64_t amount,
uint64_t fee,
std::string &payload,
std::string payload,
uint64_t ttl,
uint64_t nonce
)
: sender_id(sender_id)
, recipient_id(recipientId)
: sender_id(std::move(sender_id))
, recipient_id(std::move(recipientId))
, amount(amount)
, fee(fee)
, payload(payload)
, payload(std::move(payload))
, ttl(ttl)
, nonce(nonce){};

Expand Down
8 changes: 4 additions & 4 deletions src/interface/TWAeternityAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ struct TWAeternityAddress *_Nonnull TWAeternityAddressCreateWithPublicKey(struct
return new TWAeternityAddress{ Address(publicKey->impl) };
}

void TWAeternityAddressDelete(struct TWAeternityAddress *_Nonnull address) {
delete address;
}

/// Returns the address string representation.
TWString *_Nonnull TWAeternityAddressDescription(struct TWAeternityAddress *_Nonnull address){
const auto string = address->impl.string();
return TWStringCreateWithUTF8Bytes(string.c_str());
}

void TWAeternityAddressDelete(struct TWAeternityAddress *_Nonnull address) {
delete address;
}
34 changes: 9 additions & 25 deletions src/interface/TWAeternitySigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.

#include "../Aeternity/Address.h"
#include "../Aeternity/Signer.h"
#include "../Aeternity/Transaction.h"
#include "../proto/Aeternity.pb.h"
#include "../uint256.h"
#include <TrustWalletCore/TWAeternitySigner.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace TW;
using namespace TW::Aeternity;
Expand All @@ -21,28 +18,15 @@ TW_Aeternity_Proto_SigningOutput TWAeternitySignerSign(TW_Aeternity_Proto_Signin

auto privateKey = PrivateKey(Data(input.private_key().begin(), input.private_key().end()));

auto from = Address(input.from_address());
auto to = Address(input.to_address());

std::string sender_id = "ak_2p5878zbFhxnrm7meL7TmqwtvBaqcBddyp5eGzZbovZ5FeVfcw";
std::string recipient_id = "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v";
uint64_t amount = 10;
double fee = 2e13;
std::string payload = "Hello World";
uint64_t ttl = 82757;
uint64_t nonce = 49;

auto tx = Transaction(sender_id, recipient_id, amount, fee, payload, ttl, nonce);

// auto tx = Transaction(
// from,
// to,
// input.amount(),
// input.fee(),
// input.payload(),
// input.ttl(),
// input.nonce()
// );
auto tx = Transaction(
input.from_address(),
input.to_address(),
input.amount(),
input.fee(),
input.payload(),
input.ttl(),
input.nonce()
);

auto output = Signer::sign(privateKey, tx);

Expand Down

0 comments on commit 40b637a

Please sign in to comment.