Skip to content

Commit

Permalink
Updated the readme and fixed some bugs with warp transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
kpachhai committed Feb 6, 2024
1 parent 98e1dc6 commit 1277aa8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 44 deletions.
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,12 @@ When you are done, the output should look something like this:
```
database: .nuklai-cli
address: nuklai1qrzvk4zlwj9zsacqgtufx7zvapd3quufqpxk5rsdd4633m4wz2fdjss0gwx
chainID: jLqD1HxDRb54NpfK7Psb6bkhAHghF36VcokJ6kvSBGZpTT6aj
chainID: N5Chcji7s7wAxukcoanm98MdjVKVwR5W3vzcp9tv2VpRknENs
symbol: TOKEN1
decimals: 9
metadata: Example token1
decimals: 9
metadata: Example token1
✔ continue (y/n): y█
✅ txID: 2sq8ThNtmd3ijEsvYUqBgrEkJqFGW9m6b2EmiDKt6ehaFai3qA
✅ txID: ggMxHuutoobCLfuYyiLRYr1VMq7r9ULcBU621kvurtsqdifjN
```

_`txID` is the `assetID` of your new asset._
Expand All @@ -438,13 +438,13 @@ just to mint to yourself).
```
database: .nuklai-cli
address: nuklai1qrzvk4zlwj9zsacqgtufx7zvapd3quufqpxk5rsdd4633m4wz2fdjss0gwx
chainID: jLqD1HxDRb54NpfK7Psb6bkhAHghF36VcokJ6kvSBGZpTT6aj
assetID: 2sq8ThNtmd3ijEsvYUqBgrEkJqFGW9m6b2EmiDKt6ehaFai3qA
chainID: N5Chcji7s7wAxukcoanm98MdjVKVwR5W3vzcp9tv2VpRknENs
assetID: ggMxHuutoobCLfuYyiLRYr1VMq7r9ULcBU621kvurtsqdifjN
symbol: TOKEN1 decimals: 9 metadata: Example token1 supply: 0
recipient: nuklai1qrzvk4zlwj9zsacqgtufx7zvapd3quufqpxk5rsdd4633m4wz2fdjss0gwx
✔ amount: 100
✔ amount: 1000
continue (y/n): y
✅ txID: 2DzquqEAKXUgQZHgQfnaxnUjEhyFrRsna5d995Tr9Lzu7EdJ8R
✅ txID: 2eG6m32NMgaxdz36W8omF1tQNBAkXr2JHojsU67X1AQzT73PSf
```

#### Step 3: View Your Balance
Expand All @@ -461,11 +461,11 @@ When you are done, the output should look something like this:
```
database: .nuklai-cli
address: nuklai1qrzvk4zlwj9zsacqgtufx7zvapd3quufqpxk5rsdd4633m4wz2fdjss0gwx
chainID: jLqD1HxDRb54NpfK7Psb6bkhAHghF36VcokJ6kvSBGZpTT6aj
assetID (use NAI for native token): 2sq8ThNtmd3ijEsvYUqBgrEkJqFGW9m6b2EmiDKt6ehaFai3qA█
uri: http://127.0.0.1:42719/ext/bc/jLqD1HxDRb54NpfK7Psb6bkhAHghF36VcokJ6kvSBGZpTT6aj
symbol: TOKEN1 decimals: 9 metadata: Example token1 supply: 100000000000 warp: false
balance: 100.000000000 TOKEN1
chainID: N5Chcji7s7wAxukcoanm98MdjVKVwR5W3vzcp9tv2VpRknENs
assetID (use NAI for native token): ggMxHuutoobCLfuYyiLRYr1VMq7r9ULcBU621kvurtsqdifjN
uri: http://127.0.0.1:43689/ext/bc/N5Chcji7s7wAxukcoanm98MdjVKVwR5W3vzcp9tv2VpRknENs
symbol: TOKEN1 decimals: 9 metadata: Example token1 supply: 1000000000000 warp: false
balance: 1000.000000000 TOKEN1
```

### Transfer Assets to Another Subnet
Expand All @@ -483,22 +483,22 @@ When you are done, the output should look something like this:
```
database: .nuklai-cli
address: nuklai1qrzvk4zlwj9zsacqgtufx7zvapd3quufqpxk5rsdd4633m4wz2fdjss0gwx
chainID: jLqD1HxDRb54NpfK7Psb6bkhAHghF36VcokJ6kvSBGZpTT6aj
✔ assetID (use NAI for native token): NAI█
balance: 852999999.999939919 NAI
✔ recipient: nuklai1qrzvk4zlwj9zsacqgtufx7zvapd3quufqpxk5rsdd4633m4wz2fdjss0gwx█
amount: 50
reward: 0
available chains: 1 excluded: [jLqD1HxDRb54NpfK7Psb6bkhAHghF36VcokJ6kvSBGZpTT6aj]
0) chainID: Ua7vvdAAHzYG2nFaQ33kamYGnvnRPeTaHoifzB3RxyBPmubKr
chainID: N5Chcji7s7wAxukcoanm98MdjVKVwR5W3vzcp9tv2VpRknENs
✔ assetID (use NAI for native token): ggMxHuutoobCLfuYyiLRYr1VMq7r9ULcBU621kvurtsqdifjN█
symbol: TOKEN1 decimals: 9 metadata: Example token1 supply: 1000000000000 warp: false
balance: 1000.000000000 TOKEN1
recipient: nuklai1qrzvk4zlwj9zsacqgtufx7zvapd3quufqpxk5rsdd4633m4wz2fdjss0gwx
✔ amount: 50█
✔ reward: 0█
available chains: 1 excluded: [N5Chcji7s7wAxukcoanm98MdjVKVwR5W3vzcp9tv2VpRknENs]
0) chainID: qttmKGHGjHfj6749KJxaSzfD1xuhKRrFFjM6TypthH2TSxuLK
destination: 0 [auto-selected]
✔ swap on import (y/n): n█
✔ continue (y/n): y█
✅ txID: 2K4Sb9xNPsenCUcM6EXUQAqgvrPWX2e3NLUcSXNGmeRXVbytVt
continue (y/n): y
✅ txID: 2LwezG85VjTktvfZpwnGigvqH3o74ZC9qBWmWUwjsXmqAwQMsV
perform import on destination (y/n): y
3kvVpqa78MG2gTWtfKSvhPryHkKVaWhMEWQ8sL2xBAtVRiChh to: nuklai1qrzvk4zlwj9zsacqgtufx7zvapd3quufqpxk5rsdd4633m4wz2fdjss0gwx source assetID: 11111111111111111111111111111111LpoYY source symbol: NAI output assetID: wkaZgTapGBi122S9deE8XSPd3VunJK6mCBF4ZRBU72sm6Em82 value: 50.000000000 reward: 0.000000000 return: false
signature weight: 5000 total weight: 5000
✔ switch default chain to destination (y/n): y
2RiJax29P6XVQzeXXApigqBBcsmrZjJ1vXKPBv1RaTKc5mqaxW to: nuklai1qrzvk4zlwj9zsacqgtufx7zvapd3quufqpxk5rsdd4633m4wz2fdjss0gwx source assetID: ggMxHuutoobCLfuYyiLRYr1VMq7r9ULcBU621kvurtsqdifjN source symbol: TOKEN1 output assetID: 7W44tf7zcvWW9MYLLvQdoL6Uf7L5MZ2vgNdGqYJ5caeEbMiuB value: 50.000000000 reward: 0.000000000 return: false
✅ txID: FLkYqXKMmE9HwKksdmiwyJberPzq4zEeEupwHDgDcAXkhjmGX
✔ switch default chain to destination (y/n): y
```

_The `export` command will automatically run the `import` command on the
Expand Down
30 changes: 13 additions & 17 deletions cmd/nuklai-cli/cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ var mintAssetCmd = &cobra.Command{

func performImport(
ctx context.Context,
srcHcli *hrpc.JSONRPCClient,
destHcli *hrpc.JSONRPCClient,
destHws *hrpc.WebSocketClient,
destNcli *nrpc.JSONRPCClient,
hscli *hrpc.JSONRPCClient,
hdcli *hrpc.JSONRPCClient,
hws *hrpc.WebSocketClient,
ncli *nrpc.JSONRPCClient,
exportTxID ids.ID,
factory chain.AuthFactory,
) error {
Expand All @@ -389,7 +389,7 @@ func performImport(
subnetWeight, sigWeight uint64
)
for ctx.Err() == nil {
msg, subnetWeight, sigWeight, err = srcHcli.GenerateAggregateWarpSignature(ctx, exportTxID)
msg, subnetWeight, sigWeight, err = hscli.GenerateAggregateWarpSignature(ctx, exportTxID)
if sigWeight >= (subnetWeight*4)/5 && err == nil {
break
}
Expand Down Expand Up @@ -436,7 +436,7 @@ func performImport(
wt.Return,
)
if wt.SwapIn > 0 {
_, outSymbol, outDecimals, _, _, _, _, err := destNcli.Asset(ctx, wt.AssetOut, false)
_, outSymbol, outDecimals, _, _, _, _, err := ncli.Asset(ctx, wt.AssetOut, false)
if err != nil {
return err
}
Expand All @@ -450,11 +450,6 @@ func performImport(
wt.SwapExpiry,
)
}
hutils.Outf(
"{{yellow}}signature weight:{{/}} %d {{yellow}}total weight:{{/}} %d\n",
sigWeight,
subnetWeight,
)

// Select fill
var fill bool
Expand All @@ -471,15 +466,16 @@ func performImport(
// Generate transaction
_, _, err = sendAndWait(ctx, msg, &actions.ImportAsset{
Fill: fill,
}, destHcli, destHws, destNcli, factory, true)
}, hdcli, hws, ncli, factory, true)
return err
}

var importAssetCmd = &cobra.Command{
Use: "import-asset",
RunE: func(*cobra.Command, []string) error {
ctx := context.Background()
currentChainID, _, factory, dcli, dscli, dtcli, err := handler.DefaultActor()

currentChainID, _, factory, hdcli, hws, ncli, err := handler.DefaultActor()
if err != nil {
return err
}
Expand All @@ -489,10 +485,10 @@ var importAssetCmd = &cobra.Command{
if err != nil {
return err
}
scli := hrpc.NewJSONRPCClient(uris[0])
hscli := hrpc.NewJSONRPCClient(uris[0])

// Perform import
return performImport(ctx, scli, dcli, dscli, dtcli, ids.Empty, factory)
return performImport(ctx, hscli, hdcli, hws, ncli, ids.Empty, factory)
},
}

Expand Down Expand Up @@ -636,11 +632,11 @@ var exportAssetCmd = &cobra.Command{
if err != nil {
return err
}
dscli, err := hrpc.NewWebSocketClient(uris[0], hrpc.DefaultHandshakeTimeout, pubsub.MaxPendingMessages, pubsub.MaxReadMessageSize)
hdcli, err := hrpc.NewWebSocketClient(uris[0], hrpc.DefaultHandshakeTimeout, pubsub.MaxPendingMessages, pubsub.MaxReadMessageSize)
if err != nil {
return err
}
if err := performImport(ctx, hcli, hrpc.NewJSONRPCClient(uris[0]), dscli, nrpc.NewJSONRPCClient(uris[0], networkID, destination), txID, factory); err != nil {
if err := performImport(ctx, hcli, hrpc.NewJSONRPCClient(uris[0]), hdcli, nrpc.NewJSONRPCClient(uris[0], networkID, destination), txID, factory); err != nil {
return err
}
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/nuklai-cli/cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (h *Handler) DefaultActor() (
if err != nil {
return ids.Empty, nil, nil, nil, nil, nil, err
}

var factory chain.AuthFactory
switch addr[0] {
case nconsts.ED25519ID:
Expand All @@ -124,6 +125,7 @@ func (h *Handler) DefaultActor() (
default:
return ids.Empty, nil, nil, nil, nil, nil, ErrInvalidAddress
}

chainID, uris, err := h.h.GetDefaultChain(true)
if err != nil {
return ids.Empty, nil, nil, nil, nil, nil, err
Expand Down

0 comments on commit 1277aa8

Please sign in to comment.