Skip to content

Commit

Permalink
Release version 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit Goldberg committed May 23, 2019
1 parent 6a5215a commit 65f8fd4
Show file tree
Hide file tree
Showing 593 changed files with 32,932 additions and 346 deletions.
2 changes: 2 additions & 0 deletions asset_transfers_dev_guide/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
out
21 changes: 21 additions & 0 deletions asset_transfers_dev_guide/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions asset_transfers_dev_guide/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

all: generate_go generate_js

generate_go:
docker run --user $(shell id -u):$(shell id -g) --rm -v $${PWD}:/local \
openapitools/openapi-generator-cli:v3.3.3 \
generate \
--input-spec /local/spec/asset-swagger.yaml \
--generator-name go \
--config /local/go/openapi_config.json \
--output /local/go/sdk

generate_js:
docker run --user $(id -u):$(id -g) --rm -v $${PWD}:/local \
openapitools/openapi-generator-cli:v3.3.3 \
generate \
--input-spec /local/spec/asset-swagger.yaml \
--generator-name javascript \
--config /local/js/openapi_config.json \
--output /local/js/sdk
18 changes: 18 additions & 0 deletions asset_transfers_dev_guide/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Asset transfers SDKs

This repository provides the means to operate the QED-it asset transfers bundle API.

The bundle exposes an HTTP API, which is specified using the [OpenAPI specification](https://github.com/OAI/OpenAPI-Specification).

The structure of the repository is as follows:
- [spec](spec) - contains the API specification.
- [go](go):
- [sdk](go/sdk) - Go SDK, generated from the API specification.
- [examples/cmd](go/examples/cmd):
- [walletbalances](go/examples/cmd/walletbalances): Get wallet balances.
- [unlock](go/examples/cmd/unlock): Unlock a wallet.
- [transferandread](go/examples/cmd/transferandread): Transfer between wallets and observe the transfer.
- [tutorial](go/examples/cmd/tutorial): Follows the [tutorial](https://docs.qed-it.com/docs/qed-solution-docs/en/latest/docs/tutorial.html).
- [js](js):
- [sdk](js/sdk) - Javascript SDK, generated from the API specification.

112 changes: 112 additions & 0 deletions asset_transfers_dev_guide/go/examples/cmd/transferandread/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package main

import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"
"github.com/mitchellh/mapstructure"
"log"

"github.com/QED-it/asset_transfers_dev_guide/go/examples/util"
"github.com/QED-it/asset_transfers_dev_guide/go/sdk"
)

func main() {
client, _, err := util.InitAPIClient()
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't get a valid config"))
}

ctx := context.Background()

// START get address of destination wallet
diversifier := make([]byte, 11)
_, err = rand.Read(diversifier)
if err != nil {
util.HandleErrorAndExit(err)
}

getNewAddressRequest := sdk.GetNewAddressRequest{
WalletId: "dest_wallet",
Diversifier: hex.EncodeToString(diversifier),
}

getNewAddressResponse, _, err := client.WalletApi.WalletGetNewAddressPost(ctx, getNewAddressRequest)
// END get address of destination wallet

// START unlock source wallet
unlockRequest := sdk.UnlockWalletRequest{
WalletId: "source_wallet",
Authorization: "PrivacyIsAwesome",
Seconds: 600,
}

unlockWalletTask, _, err := client.NodeApi.NodeUnlockWalletPost(ctx, unlockRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't unlock wallet: %v", util.ErrorResponseString(err)))
}
unlockWalletStatus, err := util.WaitForAsyncTaskDone(ctx, unlockWalletTask.Id, client)
if err != nil {
util.HandleErrorAndExit(err)
}
if unlockWalletStatus.Result != "success" {
util.HandleErrorAndExit(fmt.Errorf("couldn't unlock wallet: %s", unlockWalletStatus.Error))
}
// END unlock source wallet

// START transfer from source to destination
transferRequest := sdk.TransferAssetRequest{
WalletId: "source_wallet",
Authorization: "PrivacyIsAwesome",
AssetId: 10,
Amount: 50,
RecipientAddress: getNewAddressResponse.RecipientAddress,
Memo: "hello there!",
}
transferAssetTask, _, err := client.WalletApi.WalletTransferAssetPost(ctx, transferRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't transfer: %v", util.ErrorResponseString(err)))
}
transferAssetStatus, err := util.WaitForAsyncTaskDone(ctx, transferAssetTask.Id, client)
if err != nil {
util.HandleErrorAndExit(err)
}
if transferAssetStatus.Result != "success" {
util.HandleErrorAndExit(fmt.Errorf("couldn't unlock wallet: %s", transferAssetStatus.Error))
}
// END transfer from source to destination

// START read transactions in the destination wallet and find this transfer
getActivityRequest := sdk.GetWalletActivityRequest{
WalletId: "dest_wallet",
NumberOfResults: 1000,
StartIndex: 0,
}

getTransactionsResponse, _, err := client.WalletApi.WalletGetActivityPost(ctx, getActivityRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't get transactions: %v", err))
}

lastTx := getTransactionsResponse.Transactions[len(getTransactionsResponse.Transactions)-1]

switch lastTx.Metadata.Type {
case "Issue":
var txContent sdk.AnalyticIssueWalletTx
err := mapstructure.Decode(lastTx.Content, &txContent)
if err != nil {
log.Fatal(err)
}
fmt.Printf("got an issue-tx with asset ID %d, amount %d and memo \"%s\"", txContent.AssetId, txContent.Amount, txContent.Memo)

case "Transfer":
var txContent sdk.AnalyticTransferWalletTx
err := mapstructure.Decode(lastTx.Content, &txContent)
if err != nil {
log.Fatal(err)
}
fmt.Printf("got an transfer-tx with asset ID %d, amount %d and memo \"%s\"", txContent.AssetId, txContent.Amount, txContent.Memo)

}
}
137 changes: 137 additions & 0 deletions asset_transfers_dev_guide/go/examples/cmd/tutorial/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package main

import (
"context"
"fmt"

"github.com/QED-it/asset_transfers_dev_guide/go/examples/util"
"github.com/QED-it/asset_transfers_dev_guide/go/sdk"
)

func main() {
client, _, err := util.InitAPIClient()
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't get a valid config"))
}

ctx := context.Background()

generateWalletRequest := sdk.GenerateWalletRequest{
WalletId: "Jane",
Authorization: "123456",
}

_, err = client.NodeApi.NodeGenerateWalletPost(ctx, generateWalletRequest)
if err != nil {
fmt.Printf("Could not generate Jane's wallet, %v\n", util.ErrorResponseString(err))
}

importWalletRequest := sdk.ImportWalletRequest{
WalletId: "bank",
EncryptedSk: "2b9a24e2eafce806cde2f03cae49a840ee4cfb408163c8d2de8264e3552b18ab5debc1def1fb446742cbec99f42ba9e2",
Authorization: "123",
Salt: "2829ca5659464e6a825b0ab19d1ac444878b8a3bb1093fb54f629ae4c1ef384d",
}

_, err = client.NodeApi.NodeImportWalletPost(ctx, importWalletRequest)
if err != nil {
fmt.Printf("Could not import the bank's wallet, %v\n", util.ErrorResponseString(err))
}

getNewAddressRequest := sdk.GetNewAddressRequest{
WalletId: "Jane",
Diversifier: "69be9d33a15535a59dd111",
}

getNewAddressResponse, _, err := client.WalletApi.WalletGetNewAddressPost(ctx, getNewAddressRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't generate address: %v", util.ErrorResponseString(err)))
}

fmt.Printf("Jane's address details: %v\n", getNewAddressResponse)

issueAssetRequest := sdk.IssueAssetRequest{
WalletId: "bank",
Authorization: "123",
RecipientAddress: getNewAddressResponse.RecipientAddress,
AssetId: 200,
Amount: 1,
Confidential: false,
Memo: "this is for you, Jane",
}

asyncTask, _, err := client.WalletApi.WalletIssueAssetPost(ctx, issueAssetRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't issue asset: %v", util.ErrorResponseString(err)))
}

issueTaskStatus, err := util.WaitForAsyncTaskDone(ctx, asyncTask.Id, client)
if err != nil {
util.HandleErrorAndExit(err)
}
if issueTaskStatus.Result != "success" { // Or == "failure"
util.HandleErrorAndExit(fmt.Errorf("couldn't issue asset: %v\nDid you configure the bank's private key?", issueTaskStatus.Error))
}

getWalletBalancesRequest := sdk.GetWalletBalanceRequest{
WalletId: "Jane",
}

getWalletBalancesResponse, _, err := client.WalletApi.WalletGetBalancesPost(ctx, getWalletBalancesRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't get wallet balances: %v", util.ErrorResponseString(err)))
}

fmt.Printf("Jane's wallet balances: %v\n", getWalletBalancesResponse)

getActivityRequest := sdk.GetWalletActivityRequest{
WalletId: "Jane",
StartIndex: 0,
NumberOfResults: 10,
}

getActivityResponse, _, err := client.WalletApi.WalletGetActivityPost(ctx, getActivityRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't get transactions: %v", util.ErrorResponseString(err)))
}

fmt.Printf("Jane's transactions: %v\n", getActivityResponse)
newBankAddressRequest := sdk.GetNewAddressRequest{
WalletId: "bank",
}

newBankAddressResponse, _, err := client.WalletApi.WalletGetNewAddressPost(ctx, newBankAddressRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't generate address for bank wallet: %v", util.ErrorResponseString(err)))
}

transferAssetRequest := sdk.TransferAssetRequest{
WalletId: "Jane",
Authorization: "123456",
RecipientAddress: newBankAddressResponse.RecipientAddress,
AssetId: 200,
Amount: 1,
Memo: "Getting rid of my asset",
}

asyncTask, _, err = client.WalletApi.WalletTransferAssetPost(ctx, transferAssetRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't transfer asset: %v", util.ErrorResponseString(err)))
}

transferTaskStatus, err := util.WaitForAsyncTaskDone(ctx, asyncTask.Id, client)
if err != nil {
util.HandleErrorAndExit(err)
}
if transferTaskStatus.Result != "success" { // or == "failure"
util.HandleErrorAndExit(fmt.Errorf("couldn't transfer asset: %v\nDoes Jane have sufficient balance?", transferTaskStatus.Error))
}

getActivityResponse, _, err = client.WalletApi.WalletGetActivityPost(ctx, getActivityRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't get transactions: %v", util.ErrorResponseString(err)))
}

fmt.Printf("Jane's transactions: %v\n", getActivityResponse)

}
39 changes: 39 additions & 0 deletions asset_transfers_dev_guide/go/examples/cmd/unlock/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"context"
"fmt"

"github.com/QED-it/asset_transfers_dev_guide/go/examples/util"
"github.com/QED-it/asset_transfers_dev_guide/go/sdk"
)

func main() {
client, _, err := util.InitAPIClient()
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't get a valid config"))
}

ctx := context.Background()

unlockRequest := sdk.UnlockWalletRequest{
WalletId: "source_wallet",
Authorization: "PrivacyIsAwesome",
Seconds: 600,
}

unlockWalletTask, _, err := client.NodeApi.NodeUnlockWalletPost(ctx, unlockRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't unlock wallet: %s", util.ErrorResponseString(err)))
}

unlockWalletStatus, err := util.WaitForAsyncTaskDone(ctx, unlockWalletTask.Id, client)
if err != nil {
util.HandleErrorAndExit(err)
}
if unlockWalletStatus.Result != "success" {
util.HandleErrorAndExit(fmt.Errorf("couldn't unlock wallet: %s", unlockWalletStatus.Error))
} else {
fmt.Println("wallet unlocked successfully")
}
}
33 changes: 33 additions & 0 deletions asset_transfers_dev_guide/go/examples/cmd/walletbalances/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"fmt"
"github.com/QED-it/asset_transfers_dev_guide/go/examples/util"
"github.com/QED-it/asset_transfers_dev_guide/go/sdk"
"context"
)

func main() {
client, _, err := util.InitAPIClient()
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't get a valid config"))
}

ctx := context.Background()

balanceRequest := sdk.GetWalletBalanceRequest{
WalletId: "source_wallet",
}

balanceResponse, _, err := client.WalletApi.WalletGetBalancesPost(ctx, balanceRequest)
if err != nil {
util.HandleErrorAndExit(fmt.Errorf("couldn't get wallet balance"))
}

for i := range balanceResponse.Assets {
assetBalance := balanceResponse.Assets[i]
fmt.Printf("asset %d has balance %d\n", assetBalance.AssetId, assetBalance.Amount)
}
}


Loading

0 comments on commit 65f8fd4

Please sign in to comment.