Skip to content

Commit

Permalink
Merge branch 'development' into improve/state-query-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae authored Feb 25, 2021
2 parents 2d088a4 + 65e7294 commit 190777b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/push_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- 9c-main
- development

jobs:
build_and_push:
Expand All @@ -17,7 +18,7 @@ jobs:
- name: login
run: docker login --username '${{ secrets.DOCKER_USERNAME }}' --password '${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}'
- name: build
run: docker build . -t planetariumhq/ninechronicles-headless:git-${{ github.sha }} --build-arg COMMIT=git-${{ github.sha }} --build-arg COMMIT=git-${{ github.sha }}
run: docker build . -t planetariumhq/ninechronicles-headless:git-${{ github.sha }} --build-arg COMMIT=git-${{ github.sha }}
- name: push git-version
run: docker push planetariumhq/ninechronicles-headless:git-${{ github.sha }}

27 changes: 16 additions & 11 deletions NineChronicles.Headless/Controllers/GraphQLController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class GraphQLController : ControllerBase
private ConcurrentDictionary<Address, long> NotificationRecords { get; }
= new ConcurrentDictionary<Address, long>();
private StandaloneContext StandaloneContext { get; }
private Address _address;

public const string RunStandaloneEndpoint = "/run-standalone";

Expand Down Expand Up @@ -115,9 +114,8 @@ public IActionResult SetPrivateKey([FromBody] SetPrivateKeyRequest request)

var privateKey = new PrivateKey(ByteUtil.ParseHex(request.PrivateKeyString));
StandaloneContext.NineChroniclesNodeService.PrivateKey = privateKey;
_address = privateKey.PublicKey.ToAddress();
var msg = $"Private key set ({privateKey.PublicKey.ToAddress()}).";
Log.Debug(msg);
var msg = $"Private key set ({StandaloneContext.NineChroniclesNodeService.PrivateKey.PublicKey.ToAddress()}).";
Log.Information("SetPrivateKey: {Msg}", msg);
return Ok(msg);
}

Expand Down Expand Up @@ -249,34 +247,41 @@ bool NeedsRefillNotification(AvatarState avatarState)

private void NotifyAction(ActionBase.ActionEvaluation<ActionBase> eval)
{
if (eval.OutputStates.UpdatedAddresses.Contains(_address))
if (StandaloneContext.NineChroniclesNodeService.PrivateKey is null)
{
if (eval.Signer == _address)
Log.Information("PrivateKey is not set. please call SetPrivateKey() first.");
return;
}
Address address = StandaloneContext.NineChroniclesNodeService.PrivateKey.PublicKey.ToAddress();
if (eval.OutputStates.UpdatedAddresses.Contains(address) || eval.Signer == address)
{
if (eval.Signer == address)
{
var type = NotificationEnum.Refill;
var msg = string.Empty;
switch (eval.Action)
{
case HackAndSlash3 has:
case HackAndSlash4 has:
type = NotificationEnum.HAS;
msg = has.stageId.ToString(CultureInfo.InvariantCulture);
break;
case CombinationConsumable2 _:
case CombinationConsumable3 _:
type = NotificationEnum.CombinationConsumable;
break;
case CombinationEquipment3 _:
case CombinationEquipment4 _:
type = NotificationEnum.CombinationEquipment;
break;
case Buy3 _:
case Buy4 _:
type = NotificationEnum.Buyer;
break;
}
Log.Information("NotifyAction: Type: {Type} MSG: {Msg}", type, msg);
var notification = new Notification(type, msg);
StandaloneContext.NotificationSubject.OnNext(notification);
}
else
{
if (eval.Action is Buy3 buy && buy.sellerAgentAddress == _address)
if (eval.Action is Buy4 buy && buy.sellerAgentAddress == address)
{
var notification = new Notification(NotificationEnum.Seller);
StandaloneContext.NotificationSubject.OnNext(notification);
Expand Down

0 comments on commit 190777b

Please sign in to comment.