Skip to content

Commit

Permalink
testnet version
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisDemyanko committed Aug 27, 2021
1 parent 4cd6a26 commit 5b7603e
Show file tree
Hide file tree
Showing 44 changed files with 397 additions and 155 deletions.
8 changes: 4 additions & 4 deletions BeamWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4844,7 +4844,7 @@
CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletTestNet.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = KNU2R94BJK;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -4922,7 +4922,7 @@
CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletTestNet.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = KNU2R94BJK;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -5008,7 +5008,7 @@
CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletMasterNet.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 26;
CURRENT_PROJECT_VERSION = 43;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = KNU2R94BJK;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -5088,7 +5088,7 @@
CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletMasterNet.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 26;
CURRENT_PROJECT_VERSION = 43;
DEVELOPMENT_TEAM = KNU2R94BJK;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
9 changes: 5 additions & 4 deletions BeamWallet/BeamSDK/AppModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef int BMRestoreType;

typedef void(^NewAddressGeneratedBlock)(BMAddress* _Nullable address, NSError* _Nullable error);
typedef void(^ExportOwnerKey)(NSString * _Nonnull key);
typedef void(^FeecalculatedBlock)(uint64_t fee, double change, uint64_t shieldedInputsFee);
typedef void(^FeecalculatedBlock)(uint64_t fee, double change, uint64_t shieldedInputsFee, double max);
typedef void(^PublicAddressBlock)(NSString * _Nonnull address);
typedef void(^ExportCSVBlock)(NSString * _Nonnull data, NSURL * _Nonnull url);

Expand All @@ -90,6 +90,7 @@ typedef void(^ExportCSVBlock)(NSString * _Nonnull data, NSURL * _Nonnull url);
@property (nonatomic) NewAddressGeneratedBlock _Nullable generatedNewAddressBlock;
@property (nonatomic) FeecalculatedBlock _Nullable feecalculatedBlock;
@property (nonatomic) PublicAddressBlock _Nullable getPublicAddressBlock;

@property (nonatomic) ExportCSVBlock _Nullable getCSVBlock;
@property (nonatomic,readwrite) NSPointerArray * _Nonnull delegates;

Expand Down Expand Up @@ -173,7 +174,7 @@ typedef void(^ExportCSVBlock)(NSString * _Nonnull data, NSURL * _Nonnull url);
-(BOOL)isToken:(NSString*_Nullable)address;
-(void)generateWithdrawAddress:(NewAddressGeneratedBlock _Nonnull )block;

-(NSString*_Nonnull)generateOfflineAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount;
-(void)generateOfflineAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount result:(PublicAddressBlock _Nonnull)block;
-(NSString*_Nonnull)generateRegularAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount isPermanentAddress:(BOOL)isPermanentAddress;
-(void)generateMaxPrivacyAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount result:(PublicAddressBlock _Nonnull)block;

Expand Down Expand Up @@ -210,7 +211,7 @@ typedef void(^ExportCSVBlock)(NSString * _Nonnull data, NSURL * _Nonnull url);
-(NSString*_Nonnull)getAddressTypeString:(BMAddressType)type;

// send
-(NSString*_Nullable)canSend:(double)amount assetId:(int)assetId fee:(double)fee to:(NSString*_Nullable)to;
-(NSString*_Nullable)canSend:(double)amount assetId:(int)assetId fee:(double)fee to:(NSString*_Nullable)to maxAmount:(double)maxAmount;
-(NSString*_Nullable)feeError:(double)fee;
-(NSString*_Nullable)canReceive:(double)amount fee:(double)fee;
-(void)send:(double)amount fee:(double)fee assetId:(int)assetId to:(NSString*_Nonnull)to from:(NSString*_Nonnull)from comment:(NSString*_Nonnull)comment isOffline:(BOOL)isOffline;
Expand Down Expand Up @@ -296,6 +297,6 @@ typedef void(^ExportCSVBlock)(NSString * _Nonnull data, NSURL * _Nonnull url);
-(void)rescan;
-(void)enableBodyRequests:(BOOL)value;


-(double)grothToBeam:(uint64_t)groth;

@end
143 changes: 81 additions & 62 deletions BeamWallet/BeamSDK/AppModel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ @implementation AppModel {
ECC::NoLeak<ECC::uintBig> passwordHash;

NSString *pathLog;
ByteBuffer lastVouchers;
ShieldedVoucherList lastVouchers;
NSString *lastWalledId;
std::string *lastWalledIdS;
}
Expand Down Expand Up @@ -1051,35 +1051,57 @@ -(void)generateWithdrawAddress:(NewAddressGeneratedBlock _Nonnull )block {
}


-(NSString*_Nonnull)generateOfflineAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount {
-(void)generateOfflineAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount result:(PublicAddressBlock _Nonnull)block {

uint64_t bAmount = round(amount * Rules::Coin);

WalletID m_walletID(Zero);
m_walletID.FromHex(walleetId.string);

auto address = walletDb->getAddress(m_walletID);

if(![lastWalledId isEqualToString:walleetId]) {
lastWalledId = walleetId;
lastVouchers = wallet->generateVouchers(address->m_OwnID, 1);
}

TxParameters offlineParameters;
offlineParameters.SetParameter(TxParameterID::TransactionType, beam::wallet::TxType::PushTransaction);
offlineParameters.SetParameter(TxParameterID::ShieldedVoucherList, lastVouchers);
offlineParameters.SetParameter(TxParameterID::PeerID, address->m_walletID);
offlineParameters.SetParameter(TxParameterID::PeerWalletIdentity, address->m_Identity);
offlineParameters.SetParameter(TxParameterID::PeerOwnID, address->m_OwnID);
offlineParameters.SetParameter(TxParameterID::IsPermanentPeerID, true);
offlineParameters.SetParameter(TxParameterID::AssetID, uint32_t(assetId));

if (bAmount > 0) {
offlineParameters.SetParameter(TxParameterID::Amount, bAmount);
}
auto func = GenerateVaucherFunc();
func.newGenerateVaucherBlock = ^(ShieldedVoucherList list) {
auto token = GenerateOfflineToken(*address, bAmount, uint32_t(assetId), list, std::string(BEAM_LIB_VERSION));
block([NSString stringWithUTF8String:token.c_str()]);
};

auto token = to_string(offlineParameters);
return [NSString stringWithUTF8String:token.c_str()];
wallet->getAsync()->generateVouchers(address->m_OwnID, 1, func);

// uint64_t bAmount = round(amount * Rules::Coin);
//
// WalletID m_walletID(Zero);
// m_walletID.FromHex(walleetId.string);
//
// auto address = walletDb->getAddress(m_walletID);
//
// if(![lastWalledId isEqualToString:walleetId]) {
//
// lastWalledId = walleetId;
//
// auto func = GenerateVaucherFunc();
// func.newGenerateVaucherBlock = ^(ShieldedVoucherList list) {
// self->lastVouchers = list;
// };
//
// wallet->getAsync()->generateVouchers(address->m_OwnID, 1, func);
// }
//
// TxParameters offlineParameters;
// offlineParameters.SetParameter(TxParameterID::TransactionType, beam::wallet::TxType::PushTransaction);
// offlineParameters.SetParameter(TxParameterID::ShieldedVoucherList, lastVouchers);
// offlineParameters.SetParameter(TxParameterID::PeerID, address->m_walletID);
// offlineParameters.SetParameter(TxParameterID::PeerWalletIdentity, address->m_Identity);
// offlineParameters.SetParameter(TxParameterID::PeerOwnID, address->m_OwnID);
// offlineParameters.SetParameter(TxParameterID::IsPermanentPeerID, true);
// offlineParameters.SetParameter(TxParameterID::AssetID, uint32_t(assetId));
//
// if (bAmount > 0) {
// offlineParameters.SetParameter(TxParameterID::Amount, bAmount);
// }
//
// auto token = to_string(offlineParameters);
// return [NSString stringWithUTF8String:token.c_str()];
}

-(NSString*_Nonnull)generateRegularAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount isPermanentAddress:(BOOL)isPermanentAddress {
Expand Down Expand Up @@ -1641,49 +1663,34 @@ -(void)editAddress:(BMAddress*_Nonnull)address {
{
[_presendedNotifications setValue:address.walletId forKey:address.walletId];

std::vector<WalletAddress> addresses = wallet->ownAddresses;
auto status = beam::wallet::WalletAddress::ExpirationStatus::AsIs;

for (int i=0; i<addresses.size(); i++)
{
NSString *wAddress = [NSString stringWithUTF8String:to_string(addresses[i].m_walletID).c_str()];
if ([wAddress isEqualToString:address.walletId])
{
addresses[i].m_label = address.label.string;
if(address.isNowExpired) {
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::Expired);
}
else if(address.isNowActive) {
if (address.isNowActiveDuration == 0){
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::Never);
}
else{
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::Auto);
}
if(address.isNowExpired) {
status = beam::wallet::WalletAddress::ExpirationStatus::Expired;
}
else if(address.isNowActive) {
if (address.isNowActiveDuration == 0){
status = beam::wallet::WalletAddress::ExpirationStatus::Never;
}
else{
status = beam::wallet::WalletAddress::ExpirationStatus::Auto;
}
}
else{
if (address.isExpired) {
status = beam::wallet::WalletAddress::ExpirationStatus::Expired;
}
else {
if (address.duration == 0) {
status = beam::wallet::WalletAddress::ExpirationStatus::Never;
}
else{
if (address.isExpired) {
[_deletedNotifications setObject:wAddress forKey:wAddress];
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::Expired);
}
else {
if (address.duration == 0) {
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::Never);
}
else {
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::AsIs);
}
}
else {
status = beam::wallet::WalletAddress::ExpirationStatus::AsIs;
}

// NSString *s = [NSString stringWithUTF8String:to_string(addresses[i].m_Identity).c_str()];

wallet->getAsync()->saveAddress(addresses[i]);

break;
}
}

wallet->getAsync()->updateAddress(walletID, address.label.string, status);
}
}
}
Expand Down Expand Up @@ -1878,8 +1885,16 @@ -(double)remainingBeam:(double)amount fee:(double)fee {
return realAmount;
}

-(NSString*_Nullable)canSend:(double)amount assetId:(int)assetId fee:(double)fee to:(NSString*_Nullable)to {
-(NSString*_Nullable)canSend:(double)amount assetId:(int)assetId fee:(double)fee to:(NSString*_Nullable)to maxAmount:(double)maxAmount {
NSString *errorString = [self sendError:amount assetId:assetId fee:fee to:to];
if (errorString == nil) {
if (amount > maxAmount && maxAmount != 0) {
NSString *amountString = [[StringManager sharedManager] realAmountString:maxAmount];
NSString *assetName = [[[AssetsManager sharedManager] getAsset:assetId] unitName];
NSString *fullName = [NSString stringWithFormat:@"%@ %@", amountString, assetName];
return [NSString stringWithFormat:[@"max_funds_error" localized], fullName];
}
}
return errorString;
}

Expand Down Expand Up @@ -1917,11 +1932,15 @@ -(void)calculateFee:(double)amount assetId:(int)assetId fee:(double)fee isShield

Amount bAmount = round(amount * Rules::Coin);
Amount bFee = fee;

wallet->getAsync()->selectCoins(bAmount, bFee, beam::Asset::ID(assetId), isShielded);
// wallet->getAsync()->calcShieldedCoinSelectionInfo(bAmount, 0, assetId, isShielded);
}

-(double)grothToBeam:(uint64_t)groth {
double real = double(groth / Rules::Coin);
return real;
}

-(NSString*)sendError:(double)amount assetId:(int)assetId fee:(double)fee checkMinAmount:(BOOL)check {

Expand Down
3 changes: 3 additions & 0 deletions BeamWallet/BeamSDK/AssetsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
-(void)changeAssets;
-(double)getRealAvailableAmount:(int)assetId;

-(NSMutableArray<BMAsset*>*_Nonnull)getAssetsWithBalance;
-(NSMutableArray<BMAsset*>*_Nonnull)getAssetsWithBalanceWithBeam;

@end

27 changes: 26 additions & 1 deletion BeamWallet/BeamSDK/AssetsManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

static NSString *assetsKey = @"assetsKeyNew";

NSArray *colors = @[@"#72fdff",@"#2acf1d",@"#ffbb54",@"#d885ff",@"#008eff",@"#ff746b",@"#91e300",@"#ffe75a",@"#9643ff",@"#395bff",@"#ff3b3b",@"#73ff7c",@"#ffa86c",@"#ff3abe",@"#00aee1",@"#ff5200",@"#6464ff",@"#ff7a21",@"#63afff",@"#c81f68"];
NSArray *colors = @[@"#72fdff",@"#2acf1d",@"#ffbb54",@"#d885ff",@"#008eff",@"#d885ff",@"#91e300",@"#ffe75a",@"#9643ff",@"#395bff",@"#ff3b3b",@"#73ff7c",@"#ffa86c",@"#ff3abe",@"#00aee1",@"#ff5200",@"#6464ff",@"#ff7a21",@"#63afff",@"#c81f68"];

@implementation AssetsManager

Expand Down Expand Up @@ -120,5 +120,30 @@ -(double)getRealAvailableAmount:(int)assetId {
return asset.realAmount;
}

-(NSMutableArray<BMAsset*>*_Nonnull)getAssetsWithBalance {
NSMutableArray *results = [NSMutableArray new];
for (BMAsset *asset in self.assets.reverseObjectEnumerator) {
if (asset.realAmount > 0 && ![asset isBeam]) {
[results addObject:asset];
}
}
return results;
}

-(NSMutableArray<BMAsset*>*_Nonnull)getAssetsWithBalanceWithBeam {
NSMutableArray *results = [NSMutableArray new];
BMAsset *beamAsset = nil;
for (BMAsset *asset in self.assets.reverseObjectEnumerator) {
if (asset.realAmount > 0 && ![asset isBeam]) {
[results addObject:asset];
}
else if ([asset isBeam]) {
beamAsset = asset;
}
}
[results insertObject:beamAsset atIndex:0];
return results;
}

@end

4 changes: 4 additions & 0 deletions BeamWallet/BeamSDK/Objects/BMAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@
-(UInt64)locked;
-(double)realLocked;

-(UInt64)change;
-(double)realChange;

-(BOOL)isBeam;
-(BOOL)isDemoX;

-(double)USD;
-(UInt64)dateUsed;
-(BOOL)isIncomming;

@end
28 changes: 25 additions & 3 deletions BeamWallet/BeamSDK/Objects/BMAsset.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,34 @@ -(BOOL)hasInProgressBalance {
return (_realSending >0 || _realReceiving > 0);
}

-(UInt64)change {
if (_realSending > 0 && _realReceiving > 0) {
return _receiving;
}
return 0;
}

-(double)realChange {
if (_realSending > 0 && _realReceiving > 0) {
return _realReceiving;
}
return 0;
}

-(UInt64)locked {
return _receiving + _maturing + _maxPrivacy;
return _maturing + _maxPrivacy + [self change];
}

-(double)realLocked {
return _realReceiving + _realMaturing + _realMaxPrivacy;
return _realMaturing + _realMaxPrivacy + [self realChange];
}

-(BOOL)isBeam {
return _assetId <= 0;
}

-(BOOL)isDemoX {
return [_unitName isEqualToString:@"DEMOX"];
return [[_unitName uppercaseString] isEqualToString:@"DEMOX"] || [[_unitName uppercaseString] isEqualToString:@"BEAMX"];
}

-(double)USD {
Expand All @@ -127,4 +141,12 @@ -(UInt64)dateUsed {
return 0;
}

-(BOOL)isIncomming {
BMTransaction *transaction = [[AssetsManager sharedManager] getLastTransaction:(int)self.assetId];
if (transaction != nil && transaction.isIncome) {
return YES;
}
return NO;
}

@end
Loading

0 comments on commit 5b7603e

Please sign in to comment.