Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wasm): exposed transferAllocation and freezeAllocation on wasm #557

Merged
merged 4 commits into from Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 36 additions & 6 deletions wasmsdk/README.md
Expand Up @@ -7,26 +7,29 @@ The 0chain wasm SDK is written in Go programming language, and released with Web

### zcn.sdk.init
init wasm sdk
Input:

**Input**:
> chainID, blockWorker, signatureScheme string, minConfirmation, minSubmit, confirmationChainLength int

Output:
**Output**:
> N/A

### zcn.sdk.hideLogs
hide interactive sdk logs. default is hidden.
Input:

**Input**:
> N/A

Output:
**Output**:
> N/A

### zcn.sdk.showLogs
show interactive sdk logs. default is hidden.
Input:

**Input**:
> N/A

Output:
**Output**:
> N/A

### zcn.jsProxy.setWallet
Expand Down Expand Up @@ -59,6 +62,7 @@ set 0box host for creating free allocation.

### zcn.sdk.getEncryptedPublicKey
get encrypted public key by mnemonic

**Input**:
> mnemonic string

Expand Down Expand Up @@ -106,6 +110,7 @@ commit folder change to blockchain

### zcn.sdk.getAllocationBlobbers
get blobbers with filters for creating allocation

**Input**:
> referredBlobberURLs []string,
dataShards, parityShards int, size, expiry int64,
Expand All @@ -116,6 +121,7 @@ get blobbers with filters for creating allocation

### zcn.sdk.createAllocation
create an allocation

**Input**:
> name string, datashards, parityshards int, size, expiry int64,
minReadPrice, maxReadPrice, minWritePrice, maxWritePrice int64, lock int64,preferredBlobberIds []string
Expand All @@ -126,15 +132,38 @@ create an allocation

### zcn.sdk.listAllocations
list all allocations

**Input**:
> N/A

**Output**:
> [sdk.Allocation](https://github.com/0chain/gosdk/blob/a9e504e4a0e8fc76a05679e4ef183bb03b8db8e5/zboxcore/sdk/allocation.go#L140) array

### zcn.sdk.transferAllocation
changes the owner of an allocation. Only a curator or the current owner of the allocation, can change an allocation's ownership.

**Input**:
> allocationId, newOwnerId, newOwnerPublicKey string

**Output**:
> N/A


### zcn.sdk.freezeAllocation
freeze allocation so that data can no longer be modified

**Input**:
> allocationId string

**Output**:
> N/A




### zcn.sdk.getWalletBalance
get wallet balance

**Input**:
> clientId string

Expand All @@ -143,6 +172,7 @@ get wallet balance

### zcn.sdk.getBlobberIds
convert blobber urls to blobber ids

**Input**:
> blobberUrls []string

Expand Down
36 changes: 36 additions & 0 deletions wasmsdk/allocation.go
Expand Up @@ -78,3 +78,39 @@ func createAllocation(name string, datashards, parityshards int, size, expiry in
func listAllocations() ([]*sdk.Allocation, error) {
return sdk.GetAllocations()
}

func transferAllocation(allocationId, newOwnerId, newOwnerPublicKey string) error {
if allocationId == "" {
return RequiredArg("allocationId")
}

if newOwnerId == "" {
return RequiredArg("newOwnerId")
}

if newOwnerPublicKey == "" {
return RequiredArg("newOwnerPublicKey")
}

_, _, err := sdk.CuratorTransferAllocation(allocationId, newOwnerId, newOwnerPublicKey)

return err
}

func freezeAllocation(allocationId string) error {

_, _, err := sdk.UpdateAllocation(
"", //allocationName,
0, //size,
0, //int64(expiry/time.Second),
allocationId, // allocID,
0, //lock,
true, // setImmutable,
false, //updateTerms,
"", //addBlobberId,
"", //removeBlobberId,
)

return err

}
2 changes: 2 additions & 0 deletions wasmsdk/proxy.go
Expand Up @@ -156,6 +156,8 @@ func main() {
"getAllocationBlobbers": getAllocationBlobbers,
"getBlobberIds": getBlobberIds,
"listAllocations": listAllocations,
"transferAllocation": transferAllocation,
"freezeAllocation": freezeAllocation,

//smartcontract
"executeSmartContract": executeSmartContract,
Expand Down