Skip to content

Commit 3eb3d32

Browse files
committed
request deposit entries command
1 parent 75ff1da commit 3eb3d32

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

cli/deposit.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"os"
8+
"strings"
9+
10+
"github.com/MixinNetwork/bot-api-go-client/v3"
11+
"github.com/urfave/cli/v2"
12+
)
13+
14+
var requestDepositEntryCmdCli = &cli.Command{
15+
Name: "requestdepositentry",
16+
Action: requestDepositEntry,
17+
Flags: []cli.Flag{
18+
&cli.StringFlag{
19+
Name: "keystore,k",
20+
Usage: "keystore download from https://developers.mixin.one/dashboard",
21+
},
22+
&cli.StringFlag{
23+
Name: "chain",
24+
Usage: "the chain id",
25+
},
26+
&cli.StringFlag{
27+
Name: "members",
28+
Usage: "comma separated UUIDs",
29+
},
30+
&cli.Int64Flag{
31+
Name: "threshold",
32+
Usage: "the members threshold",
33+
},
34+
},
35+
}
36+
37+
func requestDepositEntry(c *cli.Context) error {
38+
ctx := context.Background()
39+
40+
dat, err := os.ReadFile(c.String("keystore"))
41+
if err != nil {
42+
panic(err)
43+
}
44+
var su bot.SafeUser
45+
err = json.Unmarshal([]byte(dat), &su)
46+
if err != nil {
47+
panic(err)
48+
}
49+
50+
members := strings.Split(c.String("members"), ",")
51+
entries, err := bot.CreateDepositEntry(ctx, c.String("chain"), members, c.Int64("threshold"), &su)
52+
if err != nil {
53+
return err
54+
}
55+
fmt.Println(entries[0])
56+
return nil
57+
}

cli/kernel.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,9 @@ func ClaimMintDistribution(c *cli.Context) error {
208208
if err != nil {
209209
return err
210210
}
211-
if mints[0].Inputs[0].Mint.Batch != c.Uint64("batch") {
212-
panic(mints[0].PayloadHash().String())
211+
if b := mints[0].Inputs[0].Mint.Batch; b != c.Uint64("batch") {
212+
fmt.Printf("MINT %s %d %d", mints[0].PayloadHash(), b, c.Uint64("batch"))
213+
return nil
213214
}
214215

215216
safe, err := rpc.GetUTXO(KernelRPC, mints[0].PayloadHash().String(), uint64(len(mints[0].Outputs)-2))
@@ -261,7 +262,8 @@ func ClaimMintDistribution(c *cli.Context) error {
261262
})
262263
}
263264
change := total.Sub(outputTotal)
264-
if change.String() == "0.00000001" {
265+
threshold := common.NewIntegerFromString("0.00000005")
266+
if change.Sign() > 0 && change.Cmp(threshold) < 0 {
265267
r := recipients[len(recipients)-1]
266268
r.Amount = common.NewIntegerFromString(r.Amount).Add(change).String()
267269
}

cli/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func main() {
2626
safeOutputsCmdCli,
2727
safeOutputCmdCli,
2828
withdrawalCmdCli,
29+
requestDepositEntryCmdCli,
2930
spendKernelUTXOsCmdCli,
3031
claimMintDistributionCmdCli,
3132
},

safe_user.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func RegisterSafe(ctx context.Context, userId, seed string, su *SafeUser) (*User
2727
if err != nil {
2828
return nil, err
2929
}
30+
if su.SpendPrivateKey != hex.EncodeToString(private) {
31+
panic("please use the same spend private key with tip private key")
32+
}
3033
sigBuf := ed25519.Sign(ed25519.PrivateKey(pinBuf), tipBody)
3134

3235
encryptedPIN, err := EncryptEd25519PIN(hex.EncodeToString(sigBuf), uint64(time.Now().UnixNano()), su)

0 commit comments

Comments
 (0)