OSDN Git Service

Dev wallet sa (#1204)
authormuscle_boy <shenao.78@163.com>
Wed, 1 Aug 2018 11:11:24 +0000 (19:11 +0800)
committerPaladz <yzhu101@uottawa.ca>
Wed, 1 Aug 2018 11:11:24 +0000 (19:11 +0800)
* the transaction output amout prohibit set zero

* add network access control api

* format import code style

* refactor

* code refactor

* bug fix

* the struct node_info add json field

* estimate gas support multi-sign

* add testcase of estimate gas

* add testcase

* bug fix

* add test case

* test case refactor

* list-tx,list-address,list-utxo support partition

* list-addresses list-tx list-utxo support pagging

* refactor pagging

api/accounts.go
api/page_util.go [new file with mode: 0644]
api/query.go

index cd00d21..3d8c84a 100644 (file)
@@ -98,6 +98,8 @@ func (a SortByIndex) Less(i, j int) bool { return a[i].KeyIndex < a[j].KeyIndex
 func (a *API) listAddresses(ctx context.Context, ins struct {
        AccountID    string `json:"account_id"`
        AccountAlias string `json:"account_alias"`
+       From         uint    `json:"from"`
+       Count        uint    `json:"count"`
 }) Response {
        accountID := ins.AccountID
        var target *account.Account
@@ -136,7 +138,8 @@ func (a *API) listAddresses(ctx context.Context, ins struct {
 
        // sort AddressResp by KeyIndex
        sort.Sort(SortByIndex(addresses))
-       return NewSuccessResponse(addresses)
+       start, end := getPageRange(len(addresses), ins.From, ins.Count)
+       return NewSuccessResponse(addresses[start:end])
 }
 
 type minigAddressResp struct {
diff --git a/api/page_util.go b/api/page_util.go
new file mode 100644 (file)
index 0000000..4d2ec83
--- /dev/null
@@ -0,0 +1,14 @@
+package api
+
+// Get the start and end of the page.
+func getPageRange(size int, from uint, count uint) (uint, uint) {
+       total := uint(size) 
+       if from == 0 && count == 0 {
+               return 0, total
+       }
+       start := from
+       end := from + count
+       if start > total {start = total}
+       if end > total {end = total}
+       return start, end
+}
\ No newline at end of file
index 939adbd..2b37a1e 100644 (file)
@@ -96,6 +96,8 @@ func (a *API) listTransactions(ctx context.Context, filter struct {
        AccountID   string `json:"account_id"`
        Detail      bool   `json:"detail"`
        Unconfirmed bool   `json:"unconfirmed"`
+       From        uint    `json:"from"`
+       Count       uint    `json:"count"`
 }) Response {
        transactions := []*query.AnnotatedTx{}
        var err error
@@ -127,9 +129,11 @@ func (a *API) listTransactions(ctx context.Context, filter struct {
 
        if filter.Detail == false {
                txSummary := a.wallet.GetTransactionsSummary(transactions)
-               return NewSuccessResponse(txSummary)
+               start, end := getPageRange(len(txSummary), filter.From, filter.Count)
+               return NewSuccessResponse(txSummary[start:end])
        }
-       return NewSuccessResponse(transactions)
+       start, end := getPageRange(len(transactions), filter.From, filter.Count)
+       return NewSuccessResponse(transactions[start:end])
 }
 
 // POST /get-unconfirmed-transaction
@@ -241,6 +245,8 @@ func (a *API) listUnspentOutputs(ctx context.Context, filter struct {
        ID            string `json:"id"`
        Unconfirmed   bool   `json:"unconfirmed"`
        SmartContract bool   `json:"smart_contract"`
+       From          uint    `json:"from"`
+       Count         uint    `json:"count"`
 }) Response {
        accountUTXOs := a.wallet.GetAccountUtxos(filter.ID, filter.Unconfirmed, filter.SmartContract)
 
@@ -262,8 +268,8 @@ func (a *API) listUnspentOutputs(ctx context.Context, filter struct {
                        Change:              utxo.Change,
                }}, UTXOs...)
        }
-
-       return NewSuccessResponse(UTXOs)
+       start, end := getPageRange(len(UTXOs), filter.From, filter.Count)
+       return NewSuccessResponse(UTXOs[start:end])
 }
 
 // return gasRate