fix parse balance entry and hash parent
This commit is contained in:
parent
a5ceedeb6c
commit
7de884b7e4
@ -1,6 +1,7 @@
|
||||
package wallet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil/base58"
|
||||
@ -152,23 +153,6 @@ func HashSource(source *nockchain.NockchainSource) [5]uint64 {
|
||||
}
|
||||
}
|
||||
|
||||
func HashParent(note *nockchain.NockchainNote) ([5]uint64, error) {
|
||||
nameHash := HashName(note.Name)
|
||||
lockHash, err := HashLock(note.Lock)
|
||||
if err != nil {
|
||||
return [5]uint64{}, err
|
||||
}
|
||||
|
||||
sourceHash := HashSource(note.Source)
|
||||
assetHash := crypto.Tip5HashBelts([]crypto.Belt{{Value: 1}, {Value: uint64(note.Asset)}})
|
||||
|
||||
hashSourceAsset := crypto.Tip5RehashTenCell(sourceHash, assetHash)
|
||||
|
||||
q := crypto.Tip5RehashTenCell(nameHash, crypto.Tip5RehashTenCell(lockHash, hashSourceAsset))
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func HashSeedWithoutSource(seed *nockchain.NockchainSeed) ([5]uint64, error) {
|
||||
lockHash, err := HashLock(seed.Recipient)
|
||||
if err != nil {
|
||||
@ -214,6 +198,10 @@ func HashNonce(pkPoint crypto.CheetahPoint, message [5]uint64) ([]crypto.Belt, [
|
||||
|
||||
func HashSpend(spend *nockchain.NockchainSpend) ([5]uint64, error) {
|
||||
// TODO: handle multiple sig
|
||||
if len(spend.Signatures) == 0 {
|
||||
return [5]uint64{}, fmt.Errorf("signatures can not be empty")
|
||||
}
|
||||
|
||||
sigHash, err := HashSignature(spend.Signatures[0])
|
||||
if err != nil {
|
||||
return [5]uint64{}, err
|
||||
@ -386,13 +374,16 @@ func ParseBalanceEntry(entry *nockchain.BalanceEntry) nockchain.NockchainNote {
|
||||
},
|
||||
Source: &nockchain.NockchainSource{
|
||||
Source: crypto.Tip5HashToBase58(sourceHash),
|
||||
IsCoinbase: entry.Note.Source.Coinbase,
|
||||
IsCoinbase: true,
|
||||
},
|
||||
Asset: entry.Note.Assets.Value,
|
||||
}
|
||||
}
|
||||
|
||||
func ParseTimelockIntent(timelock *nockchain.TimeLockIntent) *nockchain.TimelockIntent {
|
||||
if timelock == nil {
|
||||
return nil
|
||||
}
|
||||
switch timelock.Value.(type) {
|
||||
case *nockchain.TimeLockIntent_Absolute:
|
||||
return &nockchain.TimelockIntent{
|
||||
|
@ -331,20 +331,11 @@ func (h *GprcHandler) CreateTx(ctx context.Context, req *nockchain.CreateTxReque
|
||||
var masterKey *crypto.MasterKey
|
||||
chainCode := base58.Decode(req.ChainCode)
|
||||
key := base58.Decode(req.Key)
|
||||
_, err := crypto.CheetaPointFromBytes(key)
|
||||
if err != nil {
|
||||
// priv key
|
||||
masterKey, err = crypto.MasterKeyFromPrivKey(chainCode, key)
|
||||
masterKey, err := crypto.MasterKeyFromPrivKey(chainCode, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
masterKey = &crypto.MasterKey{
|
||||
PrivateKey: []byte{},
|
||||
PublicKey: key,
|
||||
ChainCode: chainCode,
|
||||
}
|
||||
}
|
||||
|
||||
if !req.IsMasterKey {
|
||||
index := req.Index
|
||||
if index > 1<<32 {
|
||||
@ -399,7 +390,7 @@ func (h *GprcHandler) CreateTx(ctx context.Context, req *nockchain.CreateTxReque
|
||||
return nil, fmt.Errorf("note not enough balance")
|
||||
}
|
||||
|
||||
parentHash, err := HashParent(notes[i])
|
||||
parentHash, err := HashNote(notes[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -437,7 +428,6 @@ func (h *GprcHandler) CreateTx(ctx context.Context, req *nockchain.CreateTxReque
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(masterKey.PrivateKey) != 0 {
|
||||
// sign
|
||||
chalT8, sigT8, err := ComputeSig(*masterKey, msg)
|
||||
if err != nil {
|
||||
@ -451,7 +441,6 @@ func (h *GprcHandler) CreateTx(ctx context.Context, req *nockchain.CreateTxReque
|
||||
Sig: sigT8[:],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
input := nockchain.NockchainInput{
|
||||
Name: &nockchain.NockchainName{
|
||||
|
Loading…
x
Reference in New Issue
Block a user