-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpc read withdrawal claim transaction
- Loading branch information
1 parent
e1fcd30
commit 58c9c0d
Showing
6 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package rpc | ||
|
||
import ( | ||
"encoding/hex" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/MixinNetwork/mixin/crypto" | ||
"github.com/MixinNetwork/mixin/storage" | ||
) | ||
|
||
func readWithdrawal(store storage.Store, params []any) (map[string]any, error) { | ||
if len(params) != 1 { | ||
return nil, errors.New("invalid params count") | ||
} | ||
hash, err := crypto.HashFromString(fmt.Sprint(params[1])) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ver, snap, err := store.ReadWithdrawalClaim(hash) | ||
if err != nil || ver == nil { | ||
return nil, err | ||
} | ||
|
||
data := transactionToMap(ver) | ||
data["hex"] = hex.EncodeToString(ver.Marshal()) | ||
if len(snap) > 0 { | ||
data["snapshot"] = snap | ||
} | ||
return data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package storage | ||
|
||
import ( | ||
"encoding/hex" | ||
|
||
"github.com/MixinNetwork/mixin/common" | ||
"github.com/MixinNetwork/mixin/crypto" | ||
"github.com/dgraph-io/badger/v4" | ||
) | ||
|
||
func (s *BadgerStore) ReadWithdrawalClaim(hash crypto.Hash) (*common.VersionedTransaction, string, error) { | ||
txn := s.snapshotsDB.NewTransaction(false) | ||
defer txn.Discard() | ||
|
||
key := graphWithdrawalClaimKey(hash) | ||
item, err := txn.Get(key) | ||
if err == badger.ErrKeyNotFound { | ||
return nil, "", nil | ||
} else if err != nil { | ||
return nil, "", err | ||
} | ||
val, err := item.ValueCopy(nil) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
var claim crypto.Hash | ||
if len(val) != len(claim) { | ||
panic(hex.EncodeToString(val)) | ||
} | ||
copy(claim[:], val) | ||
return readTransactionAndFinalization(txn, claim) | ||
} | ||
|
||
func writeWithdrawalClaim(txn *badger.Txn, hash, claim crypto.Hash) error { | ||
tx, snap, err := readTransactionAndFinalization(txn, hash) | ||
if err != nil { | ||
return err | ||
} | ||
if tx == nil || len(snap) != 64 { | ||
panic(claim.String()) | ||
} | ||
key := graphWithdrawalClaimKey(hash) | ||
return txn.Set(key, claim[:]) | ||
} | ||
|
||
func graphWithdrawalClaimKey(tx crypto.Hash) []byte { | ||
return append([]byte(graphPrefixWithdrawal), tx[:]...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters