Skip to content

Commit 5b7603e

Browse files
committed
testnet version
1 parent 4cd6a26 commit 5b7603e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+397
-155
lines changed

BeamWallet.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4844,7 +4844,7 @@
48444844
CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletTestNet.entitlements;
48454845
CODE_SIGN_IDENTITY = "iPhone Developer";
48464846
CODE_SIGN_STYLE = Automatic;
4847-
CURRENT_PROJECT_VERSION = 1;
4847+
CURRENT_PROJECT_VERSION = 2;
48484848
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
48494849
DEVELOPMENT_TEAM = KNU2R94BJK;
48504850
ENABLE_BITCODE = NO;
@@ -4922,7 +4922,7 @@
49224922
CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletTestNet.entitlements;
49234923
CODE_SIGN_IDENTITY = "iPhone Developer";
49244924
CODE_SIGN_STYLE = Automatic;
4925-
CURRENT_PROJECT_VERSION = 1;
4925+
CURRENT_PROJECT_VERSION = 2;
49264926
DEVELOPMENT_TEAM = KNU2R94BJK;
49274927
ENABLE_BITCODE = NO;
49284928
FRAMEWORK_SEARCH_PATHS = (
@@ -5008,7 +5008,7 @@
50085008
CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletMasterNet.entitlements;
50095009
CODE_SIGN_IDENTITY = "iPhone Developer";
50105010
CODE_SIGN_STYLE = Automatic;
5011-
CURRENT_PROJECT_VERSION = 26;
5011+
CURRENT_PROJECT_VERSION = 43;
50125012
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
50135013
DEVELOPMENT_TEAM = KNU2R94BJK;
50145014
ENABLE_BITCODE = NO;
@@ -5088,7 +5088,7 @@
50885088
CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletMasterNet.entitlements;
50895089
CODE_SIGN_IDENTITY = "iPhone Developer";
50905090
CODE_SIGN_STYLE = Automatic;
5091-
CURRENT_PROJECT_VERSION = 26;
5091+
CURRENT_PROJECT_VERSION = 43;
50925092
DEVELOPMENT_TEAM = KNU2R94BJK;
50935093
ENABLE_BITCODE = NO;
50945094
FRAMEWORK_SEARCH_PATHS = (

BeamWallet/BeamSDK/AppModel.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ typedef int BMRestoreType;
8181

8282
typedef void(^NewAddressGeneratedBlock)(BMAddress* _Nullable address, NSError* _Nullable error);
8383
typedef void(^ExportOwnerKey)(NSString * _Nonnull key);
84-
typedef void(^FeecalculatedBlock)(uint64_t fee, double change, uint64_t shieldedInputsFee);
84+
typedef void(^FeecalculatedBlock)(uint64_t fee, double change, uint64_t shieldedInputsFee, double max);
8585
typedef void(^PublicAddressBlock)(NSString * _Nonnull address);
8686
typedef void(^ExportCSVBlock)(NSString * _Nonnull data, NSURL * _Nonnull url);
8787

@@ -90,6 +90,7 @@ typedef void(^ExportCSVBlock)(NSString * _Nonnull data, NSURL * _Nonnull url);
9090
@property (nonatomic) NewAddressGeneratedBlock _Nullable generatedNewAddressBlock;
9191
@property (nonatomic) FeecalculatedBlock _Nullable feecalculatedBlock;
9292
@property (nonatomic) PublicAddressBlock _Nullable getPublicAddressBlock;
93+
9394
@property (nonatomic) ExportCSVBlock _Nullable getCSVBlock;
9495
@property (nonatomic,readwrite) NSPointerArray * _Nonnull delegates;
9596

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

176-
-(NSString*_Nonnull)generateOfflineAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount;
177+
-(void)generateOfflineAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount result:(PublicAddressBlock _Nonnull)block;
177178
-(NSString*_Nonnull)generateRegularAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount isPermanentAddress:(BOOL)isPermanentAddress;
178179
-(void)generateMaxPrivacyAddress:(NSString*_Nonnull)walleetId assetId:(int)assetId amount:(double)amount result:(PublicAddressBlock _Nonnull)block;
179180

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

212213
// send
213-
-(NSString*_Nullable)canSend:(double)amount assetId:(int)assetId fee:(double)fee to:(NSString*_Nullable)to;
214+
-(NSString*_Nullable)canSend:(double)amount assetId:(int)assetId fee:(double)fee to:(NSString*_Nullable)to maxAmount:(double)maxAmount;
214215
-(NSString*_Nullable)feeError:(double)fee;
215216
-(NSString*_Nullable)canReceive:(double)amount fee:(double)fee;
216217
-(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;
@@ -296,6 +297,6 @@ typedef void(^ExportCSVBlock)(NSString * _Nonnull data, NSURL * _Nonnull url);
296297
-(void)rescan;
297298
-(void)enableBodyRequests:(BOOL)value;
298299

299-
300+
-(double)grothToBeam:(uint64_t)groth;
300301

301302
@end

BeamWallet/BeamSDK/AppModel.mm

Lines changed: 81 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ @implementation AppModel {
138138
ECC::NoLeak<ECC::uintBig> passwordHash;
139139

140140
NSString *pathLog;
141-
ByteBuffer lastVouchers;
141+
ShieldedVoucherList lastVouchers;
142142
NSString *lastWalledId;
143143
std::string *lastWalledIdS;
144144
}
@@ -1051,35 +1051,57 @@ -(void)generateWithdrawAddress:(NewAddressGeneratedBlock _Nonnull )block {
10511051
}
10521052

10531053

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

10561056
uint64_t bAmount = round(amount * Rules::Coin);
1057-
1057+
10581058
WalletID m_walletID(Zero);
10591059
m_walletID.FromHex(walleetId.string);
10601060

10611061
auto address = walletDb->getAddress(m_walletID);
10621062

1063-
if(![lastWalledId isEqualToString:walleetId]) {
1064-
lastWalledId = walleetId;
1065-
lastVouchers = wallet->generateVouchers(address->m_OwnID, 1);
1066-
}
1067-
1068-
TxParameters offlineParameters;
1069-
offlineParameters.SetParameter(TxParameterID::TransactionType, beam::wallet::TxType::PushTransaction);
1070-
offlineParameters.SetParameter(TxParameterID::ShieldedVoucherList, lastVouchers);
1071-
offlineParameters.SetParameter(TxParameterID::PeerID, address->m_walletID);
1072-
offlineParameters.SetParameter(TxParameterID::PeerWalletIdentity, address->m_Identity);
1073-
offlineParameters.SetParameter(TxParameterID::PeerOwnID, address->m_OwnID);
1074-
offlineParameters.SetParameter(TxParameterID::IsPermanentPeerID, true);
1075-
offlineParameters.SetParameter(TxParameterID::AssetID, uint32_t(assetId));
1076-
1077-
if (bAmount > 0) {
1078-
offlineParameters.SetParameter(TxParameterID::Amount, bAmount);
1079-
}
1063+
auto func = GenerateVaucherFunc();
1064+
func.newGenerateVaucherBlock = ^(ShieldedVoucherList list) {
1065+
auto token = GenerateOfflineToken(*address, bAmount, uint32_t(assetId), list, std::string(BEAM_LIB_VERSION));
1066+
block([NSString stringWithUTF8String:token.c_str()]);
1067+
};
10801068

1081-
auto token = to_string(offlineParameters);
1082-
return [NSString stringWithUTF8String:token.c_str()];
1069+
wallet->getAsync()->generateVouchers(address->m_OwnID, 1, func);
1070+
1071+
// uint64_t bAmount = round(amount * Rules::Coin);
1072+
//
1073+
// WalletID m_walletID(Zero);
1074+
// m_walletID.FromHex(walleetId.string);
1075+
//
1076+
// auto address = walletDb->getAddress(m_walletID);
1077+
//
1078+
// if(![lastWalledId isEqualToString:walleetId]) {
1079+
//
1080+
// lastWalledId = walleetId;
1081+
//
1082+
// auto func = GenerateVaucherFunc();
1083+
// func.newGenerateVaucherBlock = ^(ShieldedVoucherList list) {
1084+
// self->lastVouchers = list;
1085+
// };
1086+
//
1087+
// wallet->getAsync()->generateVouchers(address->m_OwnID, 1, func);
1088+
// }
1089+
//
1090+
// TxParameters offlineParameters;
1091+
// offlineParameters.SetParameter(TxParameterID::TransactionType, beam::wallet::TxType::PushTransaction);
1092+
// offlineParameters.SetParameter(TxParameterID::ShieldedVoucherList, lastVouchers);
1093+
// offlineParameters.SetParameter(TxParameterID::PeerID, address->m_walletID);
1094+
// offlineParameters.SetParameter(TxParameterID::PeerWalletIdentity, address->m_Identity);
1095+
// offlineParameters.SetParameter(TxParameterID::PeerOwnID, address->m_OwnID);
1096+
// offlineParameters.SetParameter(TxParameterID::IsPermanentPeerID, true);
1097+
// offlineParameters.SetParameter(TxParameterID::AssetID, uint32_t(assetId));
1098+
//
1099+
// if (bAmount > 0) {
1100+
// offlineParameters.SetParameter(TxParameterID::Amount, bAmount);
1101+
// }
1102+
//
1103+
// auto token = to_string(offlineParameters);
1104+
// return [NSString stringWithUTF8String:token.c_str()];
10831105
}
10841106

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

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

1646-
for (int i=0; i<addresses.size(); i++)
1647-
{
1648-
NSString *wAddress = [NSString stringWithUTF8String:to_string(addresses[i].m_walletID).c_str()];
1649-
1650-
if ([wAddress isEqualToString:address.walletId])
1651-
{
1652-
addresses[i].m_label = address.label.string;
1653-
1654-
if(address.isNowExpired) {
1655-
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::Expired);
1656-
}
1657-
else if(address.isNowActive) {
1658-
if (address.isNowActiveDuration == 0){
1659-
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::Never);
1660-
}
1661-
else{
1662-
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::Auto);
1663-
}
1668+
if(address.isNowExpired) {
1669+
status = beam::wallet::WalletAddress::ExpirationStatus::Expired;
1670+
}
1671+
else if(address.isNowActive) {
1672+
if (address.isNowActiveDuration == 0){
1673+
status = beam::wallet::WalletAddress::ExpirationStatus::Never;
1674+
}
1675+
else{
1676+
status = beam::wallet::WalletAddress::ExpirationStatus::Auto;
1677+
}
1678+
}
1679+
else{
1680+
if (address.isExpired) {
1681+
status = beam::wallet::WalletAddress::ExpirationStatus::Expired;
1682+
}
1683+
else {
1684+
if (address.duration == 0) {
1685+
status = beam::wallet::WalletAddress::ExpirationStatus::Never;
16641686
}
1665-
else{
1666-
if (address.isExpired) {
1667-
[_deletedNotifications setObject:wAddress forKey:wAddress];
1668-
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::Expired);
1669-
}
1670-
else {
1671-
if (address.duration == 0) {
1672-
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::Never);
1673-
}
1674-
else {
1675-
addresses[i].setExpirationStatus(beam::wallet::WalletAddress::ExpirationStatus::AsIs);
1676-
}
1677-
}
1687+
else {
1688+
status = beam::wallet::WalletAddress::ExpirationStatus::AsIs;
16781689
}
1679-
1680-
// NSString *s = [NSString stringWithUTF8String:to_string(addresses[i].m_Identity).c_str()];
1681-
1682-
wallet->getAsync()->saveAddress(addresses[i]);
1683-
1684-
break;
16851690
}
16861691
}
1692+
1693+
wallet->getAsync()->updateAddress(walletID, address.label.string, status);
16871694
}
16881695
}
16891696
}
@@ -1878,8 +1885,16 @@ -(double)remainingBeam:(double)amount fee:(double)fee {
18781885
return realAmount;
18791886
}
18801887

1881-
-(NSString*_Nullable)canSend:(double)amount assetId:(int)assetId fee:(double)fee to:(NSString*_Nullable)to {
1888+
-(NSString*_Nullable)canSend:(double)amount assetId:(int)assetId fee:(double)fee to:(NSString*_Nullable)to maxAmount:(double)maxAmount {
18821889
NSString *errorString = [self sendError:amount assetId:assetId fee:fee to:to];
1890+
if (errorString == nil) {
1891+
if (amount > maxAmount && maxAmount != 0) {
1892+
NSString *amountString = [[StringManager sharedManager] realAmountString:maxAmount];
1893+
NSString *assetName = [[[AssetsManager sharedManager] getAsset:assetId] unitName];
1894+
NSString *fullName = [NSString stringWithFormat:@"%@ %@", amountString, assetName];
1895+
return [NSString stringWithFormat:[@"max_funds_error" localized], fullName];
1896+
}
1897+
}
18831898
return errorString;
18841899
}
18851900

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

19181933
Amount bAmount = round(amount * Rules::Coin);
19191934
Amount bFee = fee;
1920-
1935+
19211936
wallet->getAsync()->selectCoins(bAmount, bFee, beam::Asset::ID(assetId), isShielded);
19221937
// wallet->getAsync()->calcShieldedCoinSelectionInfo(bAmount, 0, assetId, isShielded);
19231938
}
19241939

1940+
-(double)grothToBeam:(uint64_t)groth {
1941+
double real = double(groth / Rules::Coin);
1942+
return real;
1943+
}
19251944

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

BeamWallet/BeamSDK/AssetsManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
-(void)changeAssets;
3838
-(double)getRealAvailableAmount:(int)assetId;
3939

40+
-(NSMutableArray<BMAsset*>*_Nonnull)getAssetsWithBalance;
41+
-(NSMutableArray<BMAsset*>*_Nonnull)getAssetsWithBalanceWithBeam;
42+
4043
@end
4144

BeamWallet/BeamSDK/AssetsManager.mm

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
static NSString *assetsKey = @"assetsKeyNew";
2626

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

2929
@implementation AssetsManager
3030

@@ -120,5 +120,30 @@ -(double)getRealAvailableAmount:(int)assetId {
120120
return asset.realAmount;
121121
}
122122

123+
-(NSMutableArray<BMAsset*>*_Nonnull)getAssetsWithBalance {
124+
NSMutableArray *results = [NSMutableArray new];
125+
for (BMAsset *asset in self.assets.reverseObjectEnumerator) {
126+
if (asset.realAmount > 0 && ![asset isBeam]) {
127+
[results addObject:asset];
128+
}
129+
}
130+
return results;
131+
}
132+
133+
-(NSMutableArray<BMAsset*>*_Nonnull)getAssetsWithBalanceWithBeam {
134+
NSMutableArray *results = [NSMutableArray new];
135+
BMAsset *beamAsset = nil;
136+
for (BMAsset *asset in self.assets.reverseObjectEnumerator) {
137+
if (asset.realAmount > 0 && ![asset isBeam]) {
138+
[results addObject:asset];
139+
}
140+
else if ([asset isBeam]) {
141+
beamAsset = asset;
142+
}
143+
}
144+
[results insertObject:beamAsset atIndex:0];
145+
return results;
146+
}
147+
123148
@end
124149

BeamWallet/BeamSDK/Objects/BMAsset.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@
5353
-(UInt64)locked;
5454
-(double)realLocked;
5555

56+
-(UInt64)change;
57+
-(double)realChange;
58+
5659
-(BOOL)isBeam;
5760
-(BOOL)isDemoX;
5861

5962
-(double)USD;
6063
-(UInt64)dateUsed;
64+
-(BOOL)isIncomming;
6165

6266
@end

BeamWallet/BeamSDK/Objects/BMAsset.m

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,34 @@ -(BOOL)hasInProgressBalance {
9999
return (_realSending >0 || _realReceiving > 0);
100100
}
101101

102+
-(UInt64)change {
103+
if (_realSending > 0 && _realReceiving > 0) {
104+
return _receiving;
105+
}
106+
return 0;
107+
}
108+
109+
-(double)realChange {
110+
if (_realSending > 0 && _realReceiving > 0) {
111+
return _realReceiving;
112+
}
113+
return 0;
114+
}
115+
102116
-(UInt64)locked {
103-
return _receiving + _maturing + _maxPrivacy;
117+
return _maturing + _maxPrivacy + [self change];
104118
}
105119

106120
-(double)realLocked {
107-
return _realReceiving + _realMaturing + _realMaxPrivacy;
121+
return _realMaturing + _realMaxPrivacy + [self realChange];
108122
}
109123

110124
-(BOOL)isBeam {
111125
return _assetId <= 0;
112126
}
113127

114128
-(BOOL)isDemoX {
115-
return [_unitName isEqualToString:@"DEMOX"];
129+
return [[_unitName uppercaseString] isEqualToString:@"DEMOX"] || [[_unitName uppercaseString] isEqualToString:@"BEAMX"];
116130
}
117131

118132
-(double)USD {
@@ -127,4 +141,12 @@ -(UInt64)dateUsed {
127141
return 0;
128142
}
129143

144+
-(BOOL)isIncomming {
145+
BMTransaction *transaction = [[AssetsManager sharedManager] getLastTransaction:(int)self.assetId];
146+
if (transaction != nil && transaction.isIncome) {
147+
return YES;
148+
}
149+
return NO;
150+
}
151+
130152
@end

0 commit comments

Comments
 (0)