generated from CareBoo/UPMTemplate-2020
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(abi): add
ArgsArray
, making it easy to pass in IAbiValue
par…
…ams to AtomicTxn Builder
- Loading branch information
1 parent
f765159
commit 523d765
Showing
4 changed files
with
150 additions
and
5 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
Runtime/CareBoo.AlgoSdk/SmartContracts/Abi/Args/ArgsArray.cs
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,65 @@ | ||
using Unity.Collections; | ||
|
||
namespace AlgoSdk.Abi | ||
{ | ||
/// <summary> | ||
/// Represents an array of <see cref="IAbiValue"/> args given via params to an ABI method. | ||
/// </summary> | ||
public readonly struct ArgsArray | ||
: IArgEnumerator<ArgsArray> | ||
{ | ||
readonly IAbiValue[] values; | ||
|
||
readonly int current; | ||
|
||
public int Count => values?.Length ?? 0; | ||
|
||
public ArgsArray(IAbiValue[] values, int current) | ||
{ | ||
this.values = values; | ||
this.current = current; | ||
} | ||
|
||
public EncodedAbiArg EncodeCurrent(IAbiType type, AbiReferences references, Allocator allocator) | ||
{ | ||
if (Count == 0) | ||
throw new System.NotSupportedException("ArgsArray is empty"); | ||
|
||
return values[current].Encode(type, references, allocator); | ||
} | ||
|
||
public int LengthOfCurrent(IAbiType type) | ||
{ | ||
if (Count == 0) | ||
throw new System.NotSupportedException("ArgsArray is empty"); | ||
|
||
return values[current].Length(type); | ||
} | ||
|
||
public bool TryNext(out ArgsArray next) | ||
{ | ||
var nextIndex = current + 1; | ||
if (nextIndex >= Count) | ||
{ | ||
next = this; | ||
return false; | ||
} | ||
|
||
next = new ArgsArray(values, nextIndex); | ||
return true; | ||
} | ||
|
||
public bool TryPrev(out ArgsArray prev) | ||
{ | ||
var prevIndex = current - 1; | ||
if (prevIndex < 0) | ||
{ | ||
prev = this; | ||
return false; | ||
} | ||
|
||
prev = new ArgsArray(values, prevIndex); | ||
return true; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Runtime/CareBoo.AlgoSdk/SmartContracts/Abi/Args/ArgsArray.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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