Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Breeze
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
Breeze
Commits
faaec180
Commit
faaec180
authored
May 08, 2017
by
Pieterjan Vanhoof
Committed by
GitHub
May 08, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Get address endpoint (#39)
parents
1dc3c9a7
8e626ee6
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
64 deletions
+55
-64
ApiSpecification.md
Breeze.Documentation/ApiSpecification.md
+9
-10
Wallet.postman_collection.json
...Api.Tests/Postman requests/Wallet.postman_collection.json
+6
-6
WalletController.cs
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
+12
-12
IWalletManager.cs
Breeze/src/Breeze.Wallet/IWalletManager.cs
+6
-6
CreateAddressModel.cs
Breeze/src/Breeze.Wallet/Models/CreateAddressModel.cs
+0
-28
RequestModels.cs
Breeze/src/Breeze.Wallet/Models/RequestModels.cs
+20
-0
WalletManager.cs
Breeze/src/Breeze.Wallet/WalletManager.cs
+2
-2
No files found.
Breeze.Documentation/ApiSpecification.md
View file @
faaec180
...
...
@@ -182,21 +182,20 @@ Works as expected.
"account one"
```
##
POST /wallet/address - Adds an address to an account
### Parameters
```
{
"walletName": "myFirstWallet",
"accountName": "account one",
"coinType": 0
}
`
``
##
GET /wallet/address - Gets an unused address
This endpoint will get the last address containing no transaction or will create a new address.
### Query parameters
`walletName`
(required) - the name of the wallet in which this address is contained.
`coinType`
(required) - the type of coin for which to get the address, e.g 0 for bitcoin, 105 for stratis.
`
accountName`
(required) - the name of the account in which this address is contained.
### Responses
```
"1HDypWxXWZC5KXK259EHMnrWaa2youy7Mj"
```
## GET /wallet/receive/[account1/account2] - Displays unused receive addresses of the specified wallet account
### Responses
```
...
...
Breeze/src/Breeze.Api.Tests/Postman requests/Wallet.postman_collection.json
View file @
faaec180
...
...
@@ -2,7 +2,7 @@
"variables"
:
[],
"info"
:
{
"name"
:
"Wallet"
,
"_postman_id"
:
"5
eec0912-fcf0-50f5-05a2-0835fa13c670
"
,
"_postman_id"
:
"5
7013f2c-02dc-df32-41e9-6e4aaa14ad5e
"
,
"description"
:
"Requests relating to operations on the wallet"
,
"schema"
:
"https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
...
...
@@ -81,7 +81,7 @@
],
"body"
:
{
"mode"
:
"raw"
,
"raw"
:
"{
\n\t\"
password
\"
:
\"
123456
\"
,
\n\t\"
network
\"
:
\"
Main
\"
,
\n\t\"
folderPath
\"
:
\"
Wallets
\"
,
\n\t\"
name
\"
:
\"
my
FirstWalletRecovered
\"
,
\n\t\"
mnemonic
\"
:
\"
elbow scale error joke labor page beyond curve indicate exit brass laundry
\"\n\t
\n
}"
"raw"
:
"{
\n\t\"
password
\"
:
\"
123456
\"
,
\n\t\"
network
\"
:
\"
Main
\"
,
\n\t\"
folderPath
\"
:
\"
Wallets
\"
,
\n\t\"
name
\"
:
\"
my
RecoveredWallet
\"
,
\n\t\"
mnemonic
\"
:
\"
elbow scale error joke labor page beyond curve indicate exit brass laundry
\"
,
\n\t\"
creationDate
\"
:
\"
2016-02-25 16:20:33
\"
\n
}"
},
"description"
:
""
},
...
...
@@ -248,10 +248,10 @@
"response"
:
[]
},
{
"name"
:
"
Create new address for
wallet"
,
"name"
:
"
Get unused address in
wallet"
,
"request"
:
{
"url"
:
"http://localhost:5000/api/v1/wallet/address"
,
"method"
:
"
POS
T"
,
"url"
:
"http://localhost:5000/api/v1/wallet/address
?walletName=wallet1&accountName=account one&coinType=0
"
,
"method"
:
"
GE
T"
,
"header"
:
[
{
"key"
:
"Content-Type"
,
...
...
@@ -261,7 +261,7 @@
],
"body"
:
{
"mode"
:
"raw"
,
"raw"
:
"
{
\n\t\"
walletName
\"
:
\"
myFirstWallet
\"
,
\n\t\"
accountName
\"
:
\"
account one
\"
,
\n\t\"
coinType
\"
: 0
\n
}
"
"raw"
:
""
},
"description"
:
""
},
...
...
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
View file @
faaec180
...
...
@@ -14,7 +14,7 @@ namespace Breeze.Wallet.Controllers
/// <summary>
/// Controller providing operations on a wallet.
/// </summary>
[
Route
(
"api/v{version:apiVersion}/[controller]"
)]
[
Route
(
"api/v{version:apiVersion}/[controller]"
)]
public
class
WalletController
:
Controller
{
private
readonly
IWalletManager
walletManager
;
...
...
@@ -60,7 +60,7 @@ namespace Breeze.Wallet.Controllers
/// </summary>
/// <param name="request">The name of the wallet to load.</param>
/// <returns></returns>
[
Route
(
"load"
)]
[
Route
(
"load"
)]
[
HttpPost
]
public
IActionResult
Load
([
FromBody
]
WalletLoadRequest
request
)
{
...
...
@@ -179,7 +179,7 @@ namespace Breeze.Wallet.Controllers
/// </summary>
/// <param name="request">The request parameters.</param>
/// <returns></returns>
[
Route
(
"history"
)]
[
Route
(
"history"
)]
[
HttpGet
]
public
IActionResult
GetHistory
([
FromQuery
]
WalletHistoryRequest
request
)
{
...
...
@@ -269,7 +269,7 @@ namespace Breeze.Wallet.Controllers
/// </summary>
/// <param name="request">The transaction parameters.</param>
/// <returns>All the details of the transaction, including the hex used to execute it.</returns>
[
Route
(
"build-transaction"
)]
[
Route
(
"build-transaction"
)]
[
HttpPost
]
public
IActionResult
BuildTransaction
([
FromBody
]
BuildTransactionRequest
request
)
{
...
...
@@ -296,7 +296,7 @@ namespace Breeze.Wallet.Controllers
/// </summary>
/// <param name="request">The hex representing the transaction.</param>
/// <returns></returns>
[
Route
(
"send-transaction"
)]
[
Route
(
"send-transaction"
)]
[
HttpPost
]
public
IActionResult
SendTransaction
([
FromBody
]
SendTransactionRequest
request
)
{
...
...
@@ -374,14 +374,14 @@ namespace Breeze.Wallet.Controllers
return
ErrorHelpers
.
BuildErrorResponse
(
HttpStatusCode
.
BadRequest
,
e
.
Message
,
e
.
ToString
());
}
}
/// <summary>
///
Creates a new address for a wallet
.
///
Gets an unused address
.
/// </summary>
/// <returns>
An address in Base58 format
.</returns>
/// <returns>
The last created and unused address or creates a new address (in Base58 format)
.</returns>
[
Route
(
"address"
)]
[
Http
Pos
t
]
public
IActionResult
CreateNewAddress
([
FromBody
]
Create
AddressModel
request
)
[
Http
Ge
t
]
public
IActionResult
GetUnusedAddress
([
FromQuery
]
GetUnused
AddressModel
request
)
{
// checks the request is valid
if
(!
this
.
ModelState
.
IsValid
)
...
...
@@ -391,8 +391,8 @@ namespace Breeze.Wallet.Controllers
}
try
{
var
result
=
this
.
walletManager
.
CreateNew
Address
(
request
.
WalletName
,
request
.
CoinType
,
request
.
AccountName
);
{
var
result
=
this
.
walletManager
.
GetUnused
Address
(
request
.
WalletName
,
request
.
CoinType
,
request
.
AccountName
);
return
this
.
Json
(
result
);
}
catch
(
Exception
e
)
...
...
Breeze/src/Breeze.Wallet/IWalletManager.cs
View file @
faaec180
...
...
@@ -64,13 +64,13 @@ namespace Breeze.Wallet
string
CreateNewAccount
(
string
walletName
,
CoinType
coinType
,
string
accountName
,
string
password
);
/// <summary>
///
Creates the new address
.
///
Gets an address that contains no transaction
.
/// </summary>
/// <param name="walletName">The name of the wallet in which this address
will be creat
ed.</param>
/// <param name="coinType">The type of coin for which to
create an account
.</param>
/// <param name="accountName">The name of the account in which this address
will be created.</param>
/// <returns>
The new
address, in Base58 format.</returns>
string
CreateNew
Address
(
string
walletName
,
CoinType
coinType
,
string
accountName
);
/// <param name="walletName">The name of the wallet in which this address
is contain
ed.</param>
/// <param name="coinType">The type of coin for which to
get the address
.</param>
/// <param name="accountName">The name of the account in which this address
is contained.</param>
/// <returns>
An unused address or a newly created
address, in Base58 format.</returns>
string
GetUnused
Address
(
string
walletName
,
CoinType
coinType
,
string
accountName
);
WalletGeneralInfoModel
GetGeneralInfo
(
string
walletName
);
...
...
Breeze/src/Breeze.Wallet/Models/CreateAddressModel.cs
deleted
100644 → 0
View file @
1dc3c9a7
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Text
;
namespace
Breeze.Wallet.Models
{
public
class
CreateAddressModel
{
/// <summary>
/// The name of the wallet in which to create the address.
/// </summary>
[
Required
]
public
string
WalletName
{
get
;
set
;
}
/// <summary>
/// The type of coin this account contains.
/// </summary>
[
Required
]
public
CoinType
CoinType
{
get
;
set
;
}
/// <summary>
/// The name of the account in which to create the address.
/// </summary>
[
Required
]
public
string
AccountName
{
get
;
set
;
}
}
}
Breeze/src/Breeze.Wallet/Models/RequestModels.cs
View file @
faaec180
...
...
@@ -94,4 +94,24 @@ namespace Breeze.Wallet.Models
public
string
Hex
{
get
;
set
;
}
}
public
class
GetUnusedAddressModel
{
/// <summary>
/// The name of the wallet from which to get the address.
/// </summary>
[
Required
]
public
string
WalletName
{
get
;
set
;
}
/// <summary>
/// The type of coin this address is for.
/// </summary>
[
Required
]
public
CoinType
CoinType
{
get
;
set
;
}
/// <summary>
/// The name of the account for which to get the address.
/// </summary>
[
Required
]
public
string
AccountName
{
get
;
set
;
}
}
}
Breeze/src/Breeze.Wallet/WalletManager.cs
View file @
faaec180
...
...
@@ -150,7 +150,7 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public
string
CreateNew
Address
(
string
walletName
,
CoinType
coinType
,
string
accountName
)
public
string
GetUnused
Address
(
string
walletName
,
CoinType
coinType
,
string
accountName
)
{
Wallet
wallet
=
this
.
Wallets
.
SingleOrDefault
(
w
=>
w
.
Name
==
walletName
);
if
(
wallet
==
null
)
...
...
@@ -175,7 +175,7 @@ namespace Breeze.Wallet
var
lastAddress
=
account
.
ExternalAddresses
.
SingleOrDefault
(
a
=>
a
.
Index
==
lastAddressIndex
);
if
(
lastAddress
!=
null
&&
!
lastAddress
.
Transactions
.
Any
())
{
throw
new
Exception
(
$"Cannot create new address in account '
{
accountName
}
' if the previous address '
{
lastAddress
.
Address
}
' has not been used."
)
;
return
lastAddress
.
Address
;
}
newAddressIndex
=
lastAddressIndex
+
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment