Skip to content

Commit 8b7a62c

Browse files
committed
updated vanity url
1 parent a2d2241 commit 8b7a62c

File tree

3 files changed

+67
-173
lines changed

3 files changed

+67
-173
lines changed

contracts/Attestation.sol

Lines changed: 0 additions & 159 deletions
This file was deleted.

contracts/VanityURL.sol

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ contract VanityURL is Ownable,Pausable {
106106
mapping (string => address) vanity_address_mapping;
107107
// This declares a state variable that mapping for address to vanityURL
108108
mapping (address => string ) address_vanity_mapping;
109+
// This declares a state variable that mapping for vanityURL to Springrole ID
110+
mapping (string => string) vanity_springrole_id_mapping;
111+
// This declares a state variable that mapping for Springrole ID to vanityURL
112+
mapping (string => string) springrole_id_vanity_mapping;
109113
/*
110114
constructor function to set token address & Pricing for reserving and token transfer address
111115
*/
@@ -126,21 +130,38 @@ contract VanityURL is Ownable,Pausable {
126130
return address_vanity_mapping[_address];
127131
}
128132

133+
/* function to retrive wallet springrole id from vanity url */
134+
function retrieveSpringroleIdForVanity(string _vanity_url) constant public returns (string) {
135+
return vanity_springrole_id_mapping[_vanity_url];
136+
}
137+
138+
/* function to retrive vanity url from address */
139+
function retrieveVanityForSpringroleId(string _springrole_id) constant public returns (string) {
140+
return springrole_id_vanity_mapping[_springrole_id];
141+
}
142+
129143
/*
130144
function to reserve vanityURL
131145
1. Checks if vanity is check is valid
132146
2. Checks if address has already a vanity url
133147
3. check if vanity url is used by any other or not
134-
4. Check if vanity url is present in reserved keyword
148+
4. Check if vanity url is present in any other spingrole id
135149
5. Transfer the token
136150
6. Update the mapping variables
137151
*/
138-
function reserve(string _vanity_url) whenNotPaused public {
152+
function reserve(string _vanity_url,string _springrole_id) whenNotPaused public {
139153
_vanity_url = _toLower(_vanity_url);
140154
require(checkForValidity(_vanity_url));
141155
require(vanity_address_mapping[_vanity_url] == address(0x0));
142156
require(bytes(address_vanity_mapping[msg.sender]).length == 0);
157+
require(bytes(springrole_id_vanity_mapping[_springrole_id]).length == 0);
158+
/* adding to vanity address mapping */
143159
vanity_address_mapping[_vanity_url] = msg.sender;
160+
/* adding to vanity springrole id mapping */
161+
vanity_springrole_id_mapping[_vanity_url] = _springrole_id;
162+
/* adding to springrole id vanity mapping */
163+
springrole_id_vanity_mapping[_springrole_id] = _vanity_url;
164+
/* adding to address vanity mapping */
144165
address_vanity_mapping[msg.sender] = _vanity_url;
145166
VanityReserved(msg.sender, _vanity_url);
146167
}
@@ -184,19 +205,25 @@ contract VanityURL is Ownable,Pausable {
184205
/*
185206
function to change Vanity URL
186207
1. Checks whether vanity URL is check is valid
187-
2. Checks if address has already a vanity url
188-
3. check if vanity url is used by any other or not
189-
4. Check if vanity url is present in reserved keyword
190-
5. Update the mapping variables
208+
2. Checks whether springrole id has already has a vanity
209+
3. Checks if address has already a vanity url
210+
4. check if vanity url is used by any other or not
211+
5. Check if vanity url is present in reserved keyword
212+
6. Update the mapping variables
191213
*/
192214

193-
function changeVanityURL(string _vanity_url) whenNotPaused public {
215+
function changeVanityURL(string _vanity_url, string _springrole_id) whenNotPaused public {
194216
require(bytes(address_vanity_mapping[msg.sender]).length != 0);
217+
require(bytes(springrole_id_vanity_mapping[_springrole_id]).length == 0);
195218
_vanity_url = _toLower(_vanity_url);
196219
require(checkForValidity(_vanity_url));
197220
require(vanity_address_mapping[_vanity_url] == address(0x0));
221+
198222
vanity_address_mapping[_vanity_url] = msg.sender;
199223
address_vanity_mapping[msg.sender] = _vanity_url;
224+
vanity_springrole_id_mapping[_vanity_url]=_springrole_id;
225+
springrole_id_vanity_mapping[_springrole_id]=_vanity_url;
226+
200227
VanityReserved(msg.sender, _vanity_url);
201228
}
202229

@@ -215,7 +242,7 @@ contract VanityURL is Ownable,Pausable {
215242
/*
216243
function to transfer ownership for Vanity URL by Owner
217244
*/
218-
function reserveVanityURLByOwner(address _to,string _vanity_url,string _data) whenNotPaused onlyOwner public {
245+
function reserveVanityURLByOwner(address _to,string _vanity_url,string _springrole_id,string _data) whenNotPaused onlyOwner public {
219246
_vanity_url = _toLower(_vanity_url);
220247
require(checkForValidity(_vanity_url));
221248
/* check if vanity url is being used by anyone */
@@ -227,6 +254,10 @@ contract VanityURL is Ownable,Pausable {
227254
delete(address_vanity_mapping[vanity_address_mapping[_vanity_url]]);
228255
/* delete from vanity mapping */
229256
delete(vanity_address_mapping[_vanity_url]);
257+
/* delete from springrole id vanity mapping */
258+
delete(springrole_id_vanity_mapping[vanity_springrole_id_mapping[_vanity_url]]);
259+
/* delete from vanity springrole id mapping */
260+
delete(vanity_springrole_id_mapping[_vanity_url]);
230261
}
231262
else
232263
{
@@ -236,6 +267,8 @@ contract VanityURL is Ownable,Pausable {
236267
/* add new address to mapping */
237268
vanity_address_mapping[_vanity_url] = _to;
238269
address_vanity_mapping[_to] = _vanity_url;
270+
springrole_id_vanity_mapping[_springrole_id] = _vanity_url;
271+
vanity_springrole_id_mapping[_vanity_url] = _springrole_id;
239272
}
240273

241274
/*
@@ -247,6 +280,10 @@ contract VanityURL is Ownable,Pausable {
247280
delete(address_vanity_mapping[vanity_address_mapping[_vanity_url]]);
248281
/* delete from vanity mapping */
249282
delete(vanity_address_mapping[_vanity_url]);
283+
/* delete from springrole id vanity mapping */
284+
delete(springrole_id_vanity_mapping[vanity_springrole_id_mapping[_vanity_url]]);
285+
/* delete from vanity springrole id mapping */
286+
delete(vanity_springrole_id_mapping[_vanity_url]);
250287
/* sending VanityReleased event */
251288
VanityReleased(_vanity_url);
252289
}

test/2_vanity.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ contract('VanityURL', function(accounts) {
1010
});
1111

1212
it("should be able to reserve a url", function() {
13-
return vanityInstance.reserve('vinay_035',{from:accounts[1]}).then(function(instance){
13+
return vanityInstance.reserve('vinay_035','srind1',{from:accounts[1]}).then(function(instance){
1414
return vanityInstance.retrieveWalletForVanity.call('vinay_035');
1515
}).then(function(result) {
1616
assert.equal(result,accounts[1],"Should be able to retrive the same wallet address");
1717
return vanityInstance.retrieveVanityForWallet.call(accounts[1]);
18+
}).then(function(result) {
19+
assert.equal(result,'vinay_035',"Should be able to retrive the same vanity");
20+
return vanityInstance.retrieveSpringroleIdForVanity.call('vinay_035');
21+
}).then(function(result) {
22+
assert.equal(result,'srind1',"Should be able to retrive the same springrole id");
23+
return vanityInstance.retrieveVanityForSpringroleId.call('srind1');
1824
}).then(function(result) {
1925
assert.equal(result,'vinay_035',"Should be able to retrive the same vanity");
2026
}).catch(function(error){
@@ -23,13 +29,19 @@ contract('VanityURL', function(accounts) {
2329
});
2430

2531
it("reserve url should be case insensitive", function() {
26-
return vanityInstance.reserve('CASEIN').then(function(instance){
32+
return vanityInstance.reserve('CASEIN','srind2').then(function(instance){
2733
return vanityInstance.retrieveWalletForVanity.call('casein');
2834
}).then(function(result) {
2935
assert.equal(result,accounts[0],"Should be able to retrive the same wallet address");
3036
return vanityInstance.retrieveVanityForWallet.call(accounts[0]);
3137
}).then(function(result) {
3238
assert.equal(result,'casein',"reserve url should be case insensitive");
39+
return vanityInstance.retrieveSpringroleIdForVanity.call('casein');
40+
}).then(function(result) {
41+
assert.equal(result,'srind2',"Should be able to retrive the same springrole id");
42+
return vanityInstance.retrieveVanityForSpringroleId.call('srind2');
43+
}).then(function(result) {
44+
assert.equal(result,'casein',"Should be able to retrive the same vanity");
3345
}).catch(function(error){
3446
assert.isUndefined(error,"should be able to reserve a url")
3547
})
@@ -85,21 +97,24 @@ contract('VanityURL', function(accounts) {
8597
return vanityInstance.retrieveWalletForVanity.call('casein');
8698
}).then(function(result){
8799
assert.equal(result,'0x0000000000000000000000000000000000000000',"owner should be able to release a vanity")
100+
return vanityInstance.retrieveSpringroleIdForVanity.call('casein');
101+
}).then(function(result){
102+
assert.equal(result,'',"owner should be able to release a vanity")
88103
}).catch(function(error){
89104
assert.isUndefined(error,"owner should be able to release a vanity")
90105
})
91106
});
92107

93108
it("owner only should be able to call reserveVanityURLByOwner", function() {
94-
return vanityInstance.reserveVanityURLByOwner(accounts[4],'testowner','0x',{from:accounts[3]}).then(function(instance){
109+
return vanityInstance.reserveVanityURLByOwner(accounts[4],'testowner','srind3','0x',{from:accounts[3]}).then(function(instance){
95110
assert.isDefined(instance,"owner only should be able to call reserveVanityURLByOwner")
96111
}).catch(function(error){
97112
assert.isDefined(error,"owner only should be able to call reserveVanityURLByOwner")
98113
})
99114
});
100115

101116
it("owner should be able to call reserveVanityURLByOwner and assign a vanity to any address", function() {
102-
return vanityInstance.reserveVanityURLByOwner(accounts[4],'testowner','0x').then(function(instance){
117+
return vanityInstance.reserveVanityURLByOwner(accounts[4],'testowner','srind3','0x').then(function(instance){
103118
return vanityInstance.retrieveWalletForVanity.call('testowner');
104119
}).then(function(result) {
105120
assert.equal(result,accounts[4],"Should be able to retrive the same wallet address");
@@ -120,17 +135,18 @@ contract('VanityURL', function(accounts) {
120135
});
121136

122137
it("should error on change vanityURL when vanity is in use", function() {
123-
return vanityInstance.changeVanityURL('vinay035',{from:accounts[3]}).then(function(instance){
138+
return vanityInstance.changeVanityURL('vinay035','srind4',{from:accounts[3]}).then(function(instance){
124139
assert.isUndefined(instance,"should error on change vanityURL when not assigned")
125140
}).catch(function(error){
126141
assert.isDefined(error,"should error on change vanityURL when not assigned")
127142
})
128143
});
129144

130145
it("should be able to change vanityURL", function() {
131-
return vanityInstance.changeVanityURL('vinay0351',{from:accounts[3]}).then(function(instance){
146+
return vanityInstance.changeVanityURL('vinay0351','srind5',{from:accounts[3]}).then(function(instance){
132147
assert.isDefined(instance,"should be able to change vanityURL")
133148
}).catch(function(error){
149+
console.log(error);
134150
assert.isUndefined(error,"should be able to change vanityURL")
135151
})
136152
});

0 commit comments

Comments
 (0)